700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Linux中单引号双引号的区别与用法

Linux中单引号双引号的区别与用法

时间:2023-09-08 16:08:32

相关推荐

Linux中单引号双引号的区别与用法

1.单引号

单引号将其中的内容都作为了字符串来,忽略所有的命令和特殊字符,类似于一个字符串的用法

echo 'This is a string'>>> This is a stringecho 'ls ./'>>> ls ./

2.双引号

双引号与单引号的区别在于其可以包含特殊字符(单引号直接输出内部字符串,不解析特殊字符;双引号内则会解析特殊字符),包括’, ", $, ,如果要忽略特殊字符,就可以利用\来转义,忽略特殊字符,作为普通字符输出:

var = 1echo '$var'>>> $varecho "$var">>> 1echo "Here 'this is a string' is a string">>> Here 'this is a string' is a stringecho "Here \"this is a string\" is a string">>> Here "this is a string" is a string

3.反引号

反引号用来包含一个命令字符串的,其中的命令会先执行,得到的结果会返回到层命令再执行:

echo `echo 'this is the inner string'`+'out' >>> this is the inner string+outecho `echo 'this is the inner \` string'`+'out' #转义反引号>>> this is the inner ` string+out

反引号类似与$(command)类似。

#一个使用例子,如果想要遍历当前文件夹及其一级子文件夹:ls $(ls) ls `ls`>>> first_folder>sub_1 ..sub_2> second_folder>sub_1 ..sub_2>

————————————————

版权声明:本文为CSDN博主「hitrjj」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:/u014636245/article/details/82919144

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