您的位置:首页 > 运维架构 > Shell

Linux shell中单引号 双引号 反引号 反斜杠的区别

2015-08-13 15:40 696 查看
反引号在Linux中起着命令替换的作用。命令替换是指shell能够将一个命令的标准输出插在一个命令行中任何位置。

echo The date is `date`

The date is Thu Aug 13 15:10:58 CST 2015

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

str="Today is Monday"

echo $str

Today is Monday

单引号告诉shell忽略所有特殊字符

testvalue=100

echo 'the testvalue is $testvalue'

the testvalue is $testvalue

双引号忽略大多数,但不包括$、\、' 。

echo "the testvalue is $testvalue"

the testvalue is 100

反斜杠一般用于转义字符

echo要让转义字符发生作用,需要使用-e选项,且转义字符要使用双引号。

echo -e "hello\nnice to meet you"

hello

nice to meet you
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: