How do you append to an already existing string?

天大地大妈咪最大 提交于 2019-11-29 20:24:48
William Pursell

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
$ string="test"
$ string="${string}test2"
$ echo $string
testtest2
#!/bin/bash
message="some text"
message="$message add some more"

echo $message

some text add some more

teststr=$'test1\n'
teststr+=$'test2\n'
echo "$teststr"
VAR=$VAR"$VARTOADD(STRING)"   
echo $VAR
Aditya
#!/bin/bash

msg1=${1} #First Parameter
msg2=${2} #Second Parameter

concatString=$msg1"$msg2" #Concatenated String
concatString2="$msg1$msg2"

echo $concatString 
echo $concatString2
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!