Linux中单引号,双引号,反引号

区别:

单引号: 所见即所得 里面的内容会原封不动显示出来
双引号: 会解析里面的变量和特殊符号
反引号: 反引号里面的内容会被优先执行

[root@alice ~]# echo '$UID'
$UID
[root@alice ~]# echo "$UID"
0
[root@alice ~]# echo `date`
Wed May 15 09:28:43 CST 2019

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


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

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


var = 1
echo '$var'
>>> $var
echo "$var"
>>> 1

echo "Here 'this is a string' is a string"
>>> Here 'this is a string' is a string
echo "Here \"this is a string\" is a string"
>>> Here "this is a string" is a string
1

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

echo `echo 'this is the inner string'`+'out' 
>>> this is the inner string+out
echo `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
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值