首页 > 系统服务 > 详细

shell编程-条件判断式

时间:2016-01-18 12:04:47      阅读:135      评论:0      收藏:0      [点我收藏+]

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

技术分享

[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]#

技术分享

技术分享

技术分享

[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编程-条件判断式

原文:http://www.cnblogs.com/jackgaolei/p/5138696.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!