How to concatenate string variables in Bash

后端 未结 30 1542
攒了一身酷
攒了一身酷 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:54

    bla=hello
    laber=kthx
    echo "${bla}ohai${laber}bye"
    

    Will output

    helloohaikthxbye
    

    This is useful when $blaohai leads to a variable not found error. Or if you have spaces or other special characters in your strings. "${foo}" properly escapes anything you put into it.

提交回复
热议问题