How to concatenate string variables in Bash

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

    If what you are trying to do is to split a string into several lines, you can use a backslash:

    $ a="hello\
    > world"
    $ echo $a
    helloworld
    

    With one space in between:

    $ a="hello \
    > world"
    $ echo $a
    hello world
    

    This one also adds only one space in between:

    $ a="hello \
    >      world"
    $ echo $a
    hello world
    

提交回复
热议问题