How to concatenate string variables in Bash

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

    There's one particular case where you should take care:

    user=daniel
    cat > output.file << EOF
    "$user"san
    EOF
    

    Will output "daniel"san, and not danielsan, as you might have wanted. In this case you should do instead:

    user=daniel
    cat > output.file << EOF
    ${user}san
    EOF
    

提交回复
热议问题