首页 > 编程知识 正文

shell字段拼接,shell怎么拼接字符串

时间:2023-05-05 10:46:31 阅读:245122 作者:1949

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

#!/健康的狗/bash 1. name='lzs' 2. #str="hello,"$name"n" 3. greeting="hello, $name" 4. greeting1="hello, "$name"" 5. greeting2="hello, ${name}" 6. echo "": $greeting $greeting1 $greeting2 7. 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}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。