给网站做优化刷活跃要收费吗,做网站公违法嘛,网页在线代理,东莞卓博人才网招聘shell单双引号区别#xff1a;
Shell脚本中很多时候都在用单引号或双引号来框住字符串#xff0c;但是他们之间是存在区别的 避免踩坑记录…
单引号 单引号中的任何字符都没有特殊含义,即一些转义字符#xff0c;$ 变量引用都会无效#xff0c;它只把他们当作一个单纯的…shell单双引号区别
Shell脚本中很多时候都在用单引号或双引号来框住字符串但是他们之间是存在区别的 避免踩坑记录…
单引号 单引号中的任何字符都没有特殊含义,即一些转义字符$ 变量引用都会无效它只把他们当作一个单纯的字符来解释 双引号 双引号类似于单引号只是它允许 shell 解释美元符号 ( $ )、反引号 ( )、反斜杠 ( \ ) 和感叹号 ( ! ) 这些字符与双引号一起使用时具有特殊含义
1.如例,看 $是否生效
rootheihei:/# x123
rootheihei:/# echo $x
123
rootheihei:/# echo $x
123
rootheihei:/# echo $x
$x可以看到单引号内的 x 未生效直接当作字符串输出了不加或加双引号的 ‘ x未生效直接当作字符串输出了不加或加双引号的 x未生效直接当作字符串输出了不加或加双引号的‘x则输出的是变量x的值
2.如例看\是否生效
rootheihei:/# z\
rootheihei:/# echo $z
\
rootheihei:/# a\
rootheihei:/# echo $a可以看到单引号的时候 \未生效双引号的时候 \生效了。这个规则对于 换行符\n制表符\t等特定符号不适用
2.1 这类特殊字符如果用echo进行输出需要echo -e 字符串才能生效 如例
rootheihei:/# echo 1\n2
1\n2
rootheihei:/# echo 1\n2
1\n2
rootheihei:/# echo -e 1\n2
1
2
rootheihei:/# echo -e 1\n2
1
2
rootheihei:/# echo 1\t2
1\t2
rootheihei:/# echo 1\t2
1\t2
rootheihei:/# echo -e 1\t2
1 2
rootheihei:/# echo -e 1\t2
1 2
rootheihei:/#3.如例看反引号()是否生效,两个反引号包起来的命令会被优先执行如
xls
#优先执行ls,再将ls执行结果赋值给x如下例
rootheihei:/# xls
rootheihei:/# yls
rootheihei:/# echo $x
1.txt 2.txt 2.txtn 3.txt
rootheihei:/# echo $y
ls
rootheihei:/#可以看到双引号内的 反引号是生效的单引号内的反引号是不生效的
4.如例看感叹号是否生效
4.1 先提一下感叹号在shell中的一些特别含义 !! 执行上一条命令 !n 执行history中指定行数的命令n为行数 !字符串字符串长度大于等于1 执行上一条以字符串为开头的命令 逻辑取反 ! 不等于 ![0-9] 除0-9之外 rootheihei:/# ls
1.txt 2.txt 2.txtn 3.txt
#执行上一条命令
rootheihei:/# !!
ls
1.txt 2.txt 2.txtn 3.txt
rootheihei:/# history |tail -n 52002 ls2003 history |tail -n 102004 clear2005 ls2006 history |tail -n 5#执行history中指定行数的命令
rootheihei:/# !2003
history |tail -n 101998 history |tail -n 11999 history |tail -n 32000 exit2001 cd test/sed2002 ls2003 history |tail -n 102004 clear2005 ls2006 history |tail -n 52007 history |tail -n 10#执行上一条以his为开头的命令
rootheihei:/# !his
history |tail -n 101998 history |tail -n 11999 history |tail -n 32000 exit2001 cd test/sed2002 ls2003 history |tail -n 102004 clear2005 ls2006 history |tail -n 52007 history |tail -n 10
rootheihei:/#
再看下当感叹号遇到双引号或单引号时会遇到怎样的化学反应
rootheihei:/# ls
1.txt 2.txt 2.txtn 3.txt
rootheihei:/# echo !!
echo ls
ls如上先执行了 ls !!执行结果应该为
rootheihei:/# !!
echo ls
ls效果是有的
rootheihei:/# ls
1.txt 2.txt 2.txtn 3.txt
rootheihei:/# echo !!
!!
rootheihei:/#在看单引号如上两个感叹号被当作普通字符串进行了输出