How do you append to an already existing string?

后端 未结 7 555
孤城傲影
孤城傲影 2020-12-12 16:38

I want append to a string so that every time I loop over it will add say \"test\" to the string.

Like in PHP you would do:

$teststr = \"test1\\n\"
$t         


        
7条回答
  •  攒了一身酷
    2020-12-12 17:21

    In classic sh, you have to do something like:

    s=test1
    s="${s}test2"
    

    (there are lots of variations on that theme, like s="$s""test2")

    In bash, you can use +=:

    s=test1
    s+=test2
    

提交回复
热议问题