How to concatenate string variables in Bash

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

    I don't know about PHP yet, but this works in Linux Bash. If you don't want to affect it to a variable, you could try this:

    read pp;  *# Assumes I will affect Hello to pp*
    pp=$( printf $pp ;printf ' World'; printf '!');
    echo $pp;
    
    >Hello World!
    

    You could place another variable instead of 'Hello' or '!'. You could concatenate more strings as well.

提交回复
热议问题