100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > shell脚本之字符串的拼接

shell脚本之字符串的拼接

时间:2023-06-03 08:13:17

相关推荐

shell脚本之字符串的拼接

我们通过一个例子来将字符串拼接详细的解释。

#!/bin/bash1. name='lzs'2. #str="hello,\"$name\"\n"3. greeting="hello, $name"4. greeting1="hello, "$name""5. greeting2="hello, ${name}"6. echo \"\": $greeting $greeting1 $greeting27. greeting3='hello, '$name''8. greeting4='hello, $name' 9. greeting5='hello, ${name}'10. echo \'\':$greeting3 $greeting4 $greeting5

(1)双引号中可以有变量,可以出现转译字符。如2输出hello “lzs”, 3输出hello, lzs,4输出hello lzs,5输出hello lzs,注意,2要将\n输出为换行,需要在echo中加-e选项

(2)单引号中任何字符都会原样输出,单引号中不能出现单独一个单引号,加转译符也不行,但能成对出现。单引号中再加一对单引号也能引用变量

如7输出hello, lzs,8输出hello $name,9输出hello, ${name}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。