shell教程–shell字符串

一、单引号(’’)

1.单引号字符串的限制:
单引号里的任何字符都会原样输出,单引号字符串中的变量是无效的;
单引号字串中不能出现单独一个的单引号(对单引号使用转义符后也不行),但可成对出现,作为字符串拼接使用。

[root@xsnq ~]# string=xsnq
[root@xsnq ~]# echo '$string'
$string

二、双引号("")

双引号的优点:
双引号里可以有变量 ;
双引号里可以出现转义字符。

[root@xsnq ~]# string=xsnq
[root@xsnq ~]# echo "$string"
xsnq

三、获取字符串长度

[root@xsnq ~]# string=xsnq
[root@xsnq ~]# echo "${#string}"
4

本文出现任何错误,请留言私信批评指正。

上一节(shell教程–shell变量)
下一节

猜你喜欢

转载自blog.csdn.net/weixin_46623617/article/details/112848137