酷云的csdn 2019-12-20
等于(equal) 较大的(greater than) less-than(小于)
[ ~]# [ 10 -gt 20 ]
[ ~]# echo $?
1
[ ~]# [ 40 -gt 20 ]
[ ~]# echo $?
0
[ ~]# FreeMem=free -h | grep Mem: | awk ‘{print $4}‘
[ ~]# echo $FreeMem
5.0G
操作符 作用
= 比较字符串内容是否相同
!= 比较字符串内容是否不同
-z 判断字符串内容是否为空
[ ~]# [ -z $String ]
[ ~]# echo $?
0
[ ~]# [ /etc/hosts = /etc/profile ]
[ ~]# echo $?
1
[ ~]# [ $LANG != "en.US" ] && echo "Not en.US"
Not en.US