單引号可以将它中間的所有任意字符還原為字面意義,實現屏蔽Shell元字符的功能。注意
不可以在兩個單引号中間單獨插入一個單引号,單引号必須成對出現。
示例1:定義一個變量,并輸出變量的值[root@localhost tmp]# TESTVAR=123456 [root@localhost tmp]# echo $TESTVAR 123456 [root@localhost tmp]#
[root@localhost tmp]# echo '$TESTVAR' $TESTVAR
即:證明單引号有能屏蔽Shell元字符的功能;
[root@localhost tmp]# echo 'testvar \' testvar \ [root@localhost tmp]#
雙引号類似于單引号,但其不會屏蔽 ' 、\和$這三個Shell元字符的含義,如果需要屏蔽
這些字符含義,必須前置一個符号\,其他字符的功能将被屏蔽(包括單引号)。也就是說,兩
個雙引号之間的單引号不必成對出現
示例1、雙引号輸入還原字面意義[root@localhost tmp]# echo "一心分享,也是一種成長,謝謝" 一心分享,也是一種成長,謝謝 [root@localhost tmp]#
[root@localhost tmp]# echo "this's table" this's table [root@localhost tmp]#
[root@localhost tmp]# echo $TESTVAR 123456 [root@localhost tmp]# echo "$TESTVAR" 123456 [root@localhost tmp]#
[root@localhost tmp]# echo "$TESTVAR" 123456 [root@localhost tmp]# echo "\$TESTVAR" $TESTVAR [root@localhost tmp]#
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!