Shell conditional judgment statement

a string judgment


 
 
Two actual combat
[root@localhost ~]# name=fengji
[root@localhost ~]# [ -z $name ] && echo yes || echo no
no
[root@localhost ~]# name=""
[root@localhost ~]# [ -z $name ] && echo yes || echo no
yes
[root@localhost ~]# aa=11
[root@localhost ~]# bb=22
[root@localhost ~]# [ "$aa" == "$bb" ] && echo yes || echo no
no
[root@localhost ~]# [ "$aa" -eq "$bb" ] && echo yes || echo no
no
[root@localhost ~]# aa=22
[root@localhost ~]# [ "$aa" -eq "$bb" ] && echo yes || echo no
yes
[root@localhost ~]# [ "$aa" == "$bb" ] && echo yes || echo no
yes
 
Three multiple conditional judgments


 
 
Four actual combat
[root@localhost ~]# aa=22
[root@localhost ~]# [ -n "$aa" -a "$aa" -gt 33 ] && echo yes || echo no
no
[root@localhost ~]# [ -n "$aa" -a "$aa" -gt 3 ] && echo yes || echo no
yes

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326167303&siteId=291194637