码迷,mamicode.com
首页 > 系统相关 > 详细

shell条件判断

时间:2019-01-30 18:38:51      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:form   XML   shell条件判断   数据   键盘   bin   mis   ram   结果   

shell条件判断(流程控制的执行由判断条件的执行结果决定)
分类:
文件状态:
-e:文件(可以是文件也可以是文件夹)是否存在
-d:是不是目录
-f:是不是文件
-w:
-r:
-x:
-L:是不是链接

字符比较:
   =
   != [ str1 != str2 ] 注意空格的使用。
   -z
   ! -z
数值比较:
    -eq
   -ne
   -gt
   -ge

-lt
-le
逻辑比较:

命令:
test:
man test
[ 选项 对象 ] :注意两边必须要有空格
[root@iLor scripts]# [ -f 1.jpg]
-bash: [: missing `]‘
[root@iLor scripts]# [-f 1.jpg ]
-bash: [-f: command not found
条件判断返回结果(echo $?)只有2种:0(真)或者非0(假)

read的使用:
read命令接收标准输入(键盘)的输入,或其他文件描述符的输入(后面在说)。得到输入后,read命令将数据放入一个标准变量中。
语法:
read –p “” arguments

数值比较:(整数比较)
int1 选项 int2
-eq:等于
-ne:不等于
-gt:大于
-ge:大于等于
-lt:小于
-le:小于等于
逻辑比较:(2个或2个以上判断条件时使用逻辑比较)
逻辑与(and) -a && 多个条件同时成立
逻辑或(or) -o|| 只要有一个条件成立就可以

       例:
       [root@iLor shell_day01_am]# [ 6 -gt 5 ] && [ 4 -lt 8 ]

[root@iLor shell_day01_am]# echo ?  
0  
[root@iLor shell_day01_am]# [ 6 -gt 5 ] && [ 4 -lt 3 ]  
[root@iLor shell_day01_am]# echo
?
1
[root@iLor shell_day01_am]# [ 6 -gt 5 ] || [ 4 -lt 3 ]
[root@iLor shell_day01_am]# echo ?  
0  
[root@iLor shell_day01_am]# [ 6 -gt 5 -o 4 -lt 3 ]  
[root@iLor shell_day01_am]# echo
?
0
注意使用-a –o与&& ||的区别
逻辑非 !
= !=
-z ! –z





shell条件判断

标签:form   XML   shell条件判断   数据   键盘   bin   mis   ram   结果   

原文地址:https://www.cnblogs.com/whatislinux/p/2efcc888ea4eb757fa7de8e4c5117e06.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!