shell编程-条件判断式

shell编程-条件判断式

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

shell编程-条件判断式_第1张图片

[root@hadoop200 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
[root@hadoop200 test]# [ -d test.sh ] && echo "yes" || echo "no"
no
[root@hadoop200 test]# [ -f test.sh ] && echo "yes" || echo "no"
yes
[root@hadoop200 test]# [ -e test.sh ] && echo "yes" || echo "no"
yes
[root@hadoop200 test]#

shell编程-条件判断式_第2张图片

shell编程-条件判断式_第3张图片

shell编程-条件判断式_第4张图片

[root@hadoop200 test]# a=10
[root@hadoop200 test]# b=20
[root@hadoop200 test]# [ $a -eq $b  ] && echo "yes" || echo "no"
no
[root@hadoop200 test]# [ $a -ne $b  ] && echo "yes" || echo "no"
yes
[root@hadoop200 test]# [ $a -gt $b  ] && echo "yes" || echo "no"
no
[root@hadoop200 test]# [ $a -lt $b  ] && echo "yes" || echo "no"
yes
[root@hadoop200 test]# [ $a -ge $b  ] && echo "yes" || echo "no"
no
[root@hadoop200 test]# [ $a -le $b  ] && echo "yes" || echo "no"
yes

shell编程-条件判断式_第5张图片

shell编程-条件判断式_第6张图片

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

转载于:https://www.cnblogs.com/jackgaolei/p/5138696.html

你可能感兴趣的:(shell编程-条件判断式)