Linux中单引号双引号反引号的用法

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

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值