shell 引号

1.反斜线

  a.能将紧随其后的单个字符视为字面意义上的字符

  b.在命令的最后使用 \ 回车,能够屏蔽提交功能,从而实现命令的多行输入

    例: 

[root@VM_0_3_centos ~]# echo \*
*
[root@VM_0_3_centos ~]# echo \>
>
[root@VM_0_3_centos ~]# find /\
> -name "test.txt"\
> -type f \
> -size +5M
find: ‘/-name’: No such file or directory
find: ‘test.txt-type’: No such file or directory
find: ‘f’: No such file or directory

2.单引号

  a.单引号将中间的所有任意字符还原为字面意思,屏蔽shell元字符的功能,单引号必须成双存在。

[root@VM_0_3_centos ~]# echo $HOME
/root
[root@VM_0_3_centos ~]# echo '$HOME'
$HOME

3.双引号

  a.类似于单引号,但是不会屏蔽 、\  $ 这三个字符。如果需要屏蔽这些字符的含义,需要在前面加入\

[root@VM_0_3_centos ~]# age=18
[root@VM_0_3_centos ~]# echo "the age of xiaoming is $age years old"
the age of xiaoming is 18 years old
[root@VM_0_3_centos ~]# echo "the age of xiaoming is \$age years old"
the age of xiaoming is $age years old

4.反引号

  a.用法与$()类似,都是用来重组命令行的,先完成引号里的命令行,然后将其结果替换出来,再重组成新的命令行,但也有不同。

    1. 反引号齐本身就对\进行了转义,保留了齐本身意思,如果我们想在反引号中起到\的特殊意义,我们必须使用2个\来进行表示。

      所以我们可以简单的想象成反引号中: \\ = \

    2. $()中则不需要考虑\的问题,与我们平常使用的一样:\ = \

[root@VM_0_3_centos ~]# echo `echo \\\\\\\w`
\\w
[root@VM_0_3_centos ~]# echo $(echo \\\\\\\w)
\\\w

猜你喜欢

转载自www.cnblogs.com/icase/p/11118935.html
今日推荐