通常更推荐使用双方引号。
001、双方引号可以避免变量的单词分割
[root@pc1 test1]# str1="aa bb" ## 测试字符串 [root@pc1 test1]# if [[ $str1 == "aa bb" ]]; then echo "yes"; fi ## 双边引号不用担心变量的单词分割 yes [root@pc1 test1]# if [ $str1 == "aa bb" ]; then echo "yes"; fi ## 单边引号发生单词分割 -bash: [: too many arguments [root@pc1 test1]# if [ "$str1" == "aa bb" ]; then echo "yes"; fi ## 单边引号如果想避免单词分割,需要使用双引号 yes
002、双边引号支持高级正则表达; 单边引号不支持
[root@pc1 test1]# if [[ aabb == aab? ]]; then echo "yes"; fi ## 双边引号支持高级正则表达 yes [root@pc1 test1]# if [ aabb == aab? ]; then echo "yes"; fi ## 单边引号不支持高级正则表达
003、
标签:test1,shell,##,引号,pc1,linux,yes,root From: https://www.cnblogs.com/liujiaxin2018/p/18020375