How to concatenate string variables in Bash

后端 未结 30 1559
攒了一身酷
攒了一身酷 2020-11-22 03:40

In PHP, strings are concatenated together as follows:

$foo = \"Hello\";
$foo .= \" World\";

Here, $foo becomes \"Hello World\"

30条回答
  •  不思量自难忘°
    2020-11-22 03:59

    foo="Hello"
    foo="${foo} World"
    echo "${foo}"
    > Hello World
    

    In general to concatenate two variables you can just write them one after another:

    a='Hello'
    b='World'
    c="${a} ${b}"
    echo "${c}"
    > Hello World
    

提交回复
热议问题