linux反引号中写.sh,Linux Shell 中的反引号,单引号,双引号

概念

反引号位 (`) 位于键盘的Tab键的上方、1键的左方。注意与单引号(’)位于Enter键的左方的区别。

在Linux中起着命令替换的作用。命令替换是指shell能够将一个命令的标准输出插在一个命令行中任何位置。

如下,shell会执行反引号中的date命令,把结果插入到echo命令显示的内容中。

[root@localhost sh]# echo The date is \`date\`

The date is 2011年 03月 14日 星期一 21:15:43 CST

单引号、双引号用于用户把带有空格的字符串赋值给变量事的分界符。

[root@localhost sh]# str="Today is Monday"

[root@localhost sh]# echo $str

Today is Monday

如果没有单引号或双引号,shell会把空格后的字符串解释为命令。

[root@localhost sh]# str=Today is Monday

bash: is: command not found

单引号和双引号的区别。单引号告诉shell忽略所有特殊字符,而双引号忽略大多数,但不包括$、\、`。

[root@localhost sh]# testvalue=100

[root@localhost sh]# echo 'The testvalue is $testvalue'

The testvalue is $testvalue

[root@localhost sh]# echo "The testvalue is $testvalue"

The testvalue is 100

场景

我在使用gitlab时,使用shell runner时,将对应的变量放在了一个单引号的命令中,但是其中的变量始终不替换,后来换成双引号就好了,所以查了一下linux下单引号双引号的区别。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值