How to concatenate string variables in Bash

后端 未结 30 1540
攒了一身酷
攒了一身酷 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 04:17

    Note that this won't work

    foo=HELLO
    bar=WORLD
    foobar=PREFIX_$foo_$bar
    

    as it seems to drop $foo and leaves you with:

    PREFIX_WORLD

    but this will work:

    foobar=PREFIX_"$foo"_"$bar"
    

    and leave you with the correct output:

    PREFIX_HELLO_WORLD

提交回复
热议问题