shell编程-条件判断式

条件判断式主要有以下6种类型:

shell编程-条件判断式

[[email protected] test]# ls -l
total 8
drwxr-xr-x 2 root root 4096 Jan 17 19:28 shell
-rw-r--r-- 1 root root    4 Jan 17 19:29 test.sh
[[email protected] test]# [ -d test.sh ] && echo "yes" || echo "no"
no
[[email protected] test]# [ -f test.sh ] && echo "yes" || echo "no"
yes
[[email protected] test]# [ -e test.sh ] && echo "yes" || echo "no"
yes
[[email protected] test]#

shell编程-条件判断式

shell编程-条件判断式

shell编程-条件判断式

[[email protected] test]# a=10
[[email protected] test]# b=20
[[email protected] test]# [ $a -eq $b  ] && echo "yes" || echo "no"
no
[[email protected] test]# [ $a -ne $b  ] && echo "yes" || echo "no"
yes
[[email protected] test]# [ $a -gt $b  ] && echo "yes" || echo "no"
no
[r[email protected] test]# [ $a -lt $b  ] && echo "yes" || echo "no"
yes
[[email protected] test]# [ $a -ge $b  ] && echo "yes" || echo "no"
no
[[email protected] test]# [ $a -le $b  ] && echo "yes" || echo "no"
yes

shell编程-条件判断式

shell编程-条件判断式

posted on 2016-01-18 11:27 jackgaolei 阅读(...) 评论(...) 编辑 收藏