字符串拼接

基本类型 / 字符串

s1="three"
s2="two"

#字符串只需并排书写即可拼接;
#= 两侧不能有空格,否则 s3 会被当作命令运行
s3="$s1, $s2"
#s3 is "three, two"

#+= 追加到末尾
s3+=", one"
#s3 is "three, two, one"

sGo="$s3, go!"
#sGo is "three, two, one, go!"

#printf -v 按格式拼接并存入变量
printf -v sFormat '%s, %s' "$s3" "go!"
#sFormat is "three, two, one, go!"

echo "sGo is $sGo"
echo "sFormat is $sFormat"