[root@lovefirewall ~]# echo $tables
[root@lovefirewall ~]# echo $switch
[root@lovefirewall ~]# [[ $tables -eq 0 ]] && switch=off || switch=on
[root@lovefirewall ~]# echo $switch
off
[root@lovefirewall ~]# unset switch
[root@lovefirewall ~]# echo $switch
[root@lovefirewall ~]# [[ $tables == ^$ ]] && switch=off || switch=on
[root@lovefirewall ~]# echo $switch
on
[root@lovefirewall ~]# unset switch
[root@lovefirewall ~]# echo $switch
[root@lovefirewall ~]# [[ $tables == [[:space:]] ]] && switch=off || switch=on
[root@lovefirewall ~]# echo $switch
on
[root@lovefirewall ~]# unset switch
[root@lovefirewall ~]# echo $switch
[root@lovefirewall ~]# [[ $tables == "" ]] && switch=off || switch=on
[root@lovefirewall ~]# echo $switch
off
[root@lovefirewall ~]# unset switch
[root@lovefirewall ~]# echo $switch
[root@lovefirewall ~]# [[ 0 == "" ]] && switch=off || switch=on
[root@lovefirewall ~]# echo $switch
on
[root@lovefirewall ~]# unset switch
[root@lovefirewall ~]# echo $tables
[root@lovefirewall ~]# echo $switch
[root@lovefirewall ~]# [[ $tables == 0 ]] && switch=off || switch=on
[root@lovefirewall ~]# echo $switch
on
[root@lovefirewall ~]#
[root@lovefirewall ~]# [[ 11.11 -eq 11.22 ]] && echo wrong || echo right
-bash: [[: 11.11: syntax error: invalid arithmetic operator (error token is ".11")
right
[root@lovefirewall ~]# [[ 11.11 == 11.22 ]] && echo wrong || echo right
right
[root@lovefirewall ~]# [[ 11.11 == 11.12 ]] && echo wrong || echo right
right
[root@lovefirewall ~]# [[ 10.10 == 10.01 ]] && echo wrong || echo right
right
[root@lovefirewall ~]#
bash shell数值比较(-eq)与字符比较(==)的区别
原文:http://blog.51cto.com/183530300/2063291