How to concatenate string variables in Bash

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

    You can concatenate without the quotes. Here is an example:

    $Variable1 Open
    $Variable2 Systems
    $Variable3 $Variable1$Variable2
    $echo $Variable3
    

    This last statement would print "OpenSystems" (without quotes).

    This is an example of a Bash script:

    v1=hello
    v2=world
    v3="$v1       $v2"
    echo $v3            # Output: hello world
    echo "$v3"          # Output: hello       world
    

提交回复
热议问题