linux下"="号与"=="号

时间:2014-07-30 23:54:55   收藏:0   阅读:427
《鸟哥的linux私房菜》基础学习篇P382中说,在bash中"="与"=="是相同的,都代表判断是否相等,只不过由于其他语言一般写法使用"==",因此建议使用后者。</p><p>但是实验时,二者还是有所不同。环境为ubuntu,3.5.0-43-generic #66~precise1-Ubuntu SMP Thu Oct 24 14:55:08 UTC 2013 i686 i686 i386 GNU/Linux。
  1 a=""
  2 b=""
  3 if [ "$a" == "$b" ]
  4 then 
  5     echo "=="
  6 else
  7     echo "!="
  8 fi
若使用"==",则会报错如下:

sh t2.sh 
t2.sh: 3: [: unexpected operator
!=


如果使用"=",则通过:

[arthur@E430 ~/workspace/test]$sh t2.sh 
==


linux下"="号与"=="号,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!