shell之引用

shell可以识别四种引用字符,单引号',双引号",反斜杠和反引号`

单引号->忽略所有特殊字符

shell会忽略单引号内的所有特殊字符
例如

echo one     two   three
echo 'one     two   three'
file=/usr/bin/python
echo '$file'
echo $file

双引号->忽略大部分特殊字符

shell会忽略双引号内的大部分特殊字符,但是会保留美元字符$反引号`反斜杠
例如

filelist=*
echo $filelist
echo '$filelist'
echo "$filelist"
echo $(pwd)
echo '$(pwd)'
echo "$(pwd)"

反斜杠->转义和续行

反斜杠会对紧跟其后的字符进行转义,该字符的所有特殊含义都会被移除。

echo >
echo >
echo "$(pwd)"
echo "$(pwd)"

如果输入行的最后一个字符为反斜杠,shell会将其作为一个续行符

echo This is 
    shell.
echo 'This is 
    shell.'
echo "This is 
    shell."

反引号或$(...)->命令替换

旧的UINX系统中使用反引号进行命令替换

echo "The date and time is `date`"

新的shell标准都采用了一种更加可取的命令替换方法$(...)

echo "The date and time is $(date)."
echo "You have $(ls | wc -l) files in your directory."
原文地址:https://www.cnblogs.com/zi-wang/p/12721937.html