expression format for conditional judgments:
File Judging type:
[[Email protected] ~]# [-E/ROOT/1] && echo yes | | echo no #注意 [] inside the space, the first command is true print Yes, otherwise print noyes[[email protected] ~]# [-F/ROOT/1] && echo yes | | Echo no yes[ [Email protected] ~]# [-D/ROOT/1] && echo yes | | Echo No No
File permission to determine the type:
[[Email protected] ~]# [-R/ROOT/1] && echo yes | | echo no yes[[email protected] ~]# [-X/ROOT/1] && echo yes | | echo no no[[email protected] ~]# [-W/ROOT/1] && echo yes | | Echo No Yes
File comparison and judgement type:
[[Email protected] ~]# [ /root/1-NT/ROOT/2] && echo yes | | echo no no[[email protected] ~]# [ /ROOT/1- OT/ROOT/2] && echo yes | | echo no yes[[email protected] ~]# [ /root/1-EF/ROOT/2] && echo yes | | echo no no[[email protected] ~]# ln
1 3[[email protected] ~]# [ /root/1-EF/ROOT/3] && echo yes | | Echo No Yes
Integer comparison judgment:
[[Email protected] ~]# [4-eq 4] && echo yes | | echo No #等于yes [[email protected] ~]# [4-ne 4] && echo yes | | echo no # #不等于no [[email protected] ~]# [5 -GT 4] && echo yes | | Echo No # #大于yes [[email protected] ~]# [5-LT 4] && echo yes | | echo no # #小于no [[email protected] ~]# [5 -ge 4] && echo yes | | Echo No # #大于等于yes [[email protected] ~]# [5-le 4] && echo yes | | echo no # #小于等于no
String-Judging:
[[Email protected] ~]# [-Z $a] && echo yes | | Echo No # #判断为空no [[email protected] ~]# [-n $a] && echo yes | | echo no # #判断非空yes [[email protected] ~]# b= Abc[[email protected] ~]# [$a = = $b] && echo yes | | echo Noyes[[email protected] ~]# [$a! = $b] && echo yes | | Echo Nono
Multi-Conditional judgment:
[[Email protected] ~]# [-N $b-Z $a] && echo yes | | Echo No # #与no [[email protected] ~]# [-N $b-O-Z $a] && echo yes | | echo no # #或yes
"Shell" conditional judgment