当前位置:网站首页>Shell programming conditional statement test command Integer value, string comparison Logical test File test
Shell programming conditional statement test command Integer value, string comparison Logical test File test
2022-07-30 23:34:00 【1701y】
目录
Shell编程条件语句
条件测试操作
test命令
Used to test whether the expression holds,若成立返回0,否则返回其他数值
It can only be used to judge whether it is true or not,Can't tell if it's correct
格式1:test 条件表达式
格式2:[ 条件表达式 ] #Square brackets and conditional expressions must be surrounded by spaces,否则会报错

文件测试
[ 操作符 文件或目录 ] #There must be spaces between square brackets and content
常见的测试操作符
-d:测试是否为目录(Directory)
-e:测试目录或文件是否存在(Exist)
-f:测试是否为文件(File)
-r:测试当前用户是否有权限读取(Read)
-w:测试当前用户是否有权限写入(Write)
-x:测试当前用户是否有权限执行(eXcute
整数值比较
[ 整数1 操作符 整数2 ]
常见的测试操作符
-eq:等于(Equal)
-ne:不等于(Not Equal)
-gt:大于(Greater Than)
-lt:小于(Lesser Than)
-le:小于或等于(Lesser or Equal)
-ge:大于或等于(Greater or Equal)

字符串比较
格式1: [ 字符串1 = 字符串2 ] [ 字符串1 != 字符串2]
格式2:[ -z 字符串 ] [ -n 字符串 ]
常用的测试操作符
=:字符串内容相同
!=:字符串内容不同,!号表示取反的意思
-z:字符串内容为空 ,Variables that are not defined or assigned a null value will be treated as empty strings



逻辑测试
格式1:[ 表达式1 ] 操作符 [ 表达式2 ] ...
格式2:命令1 操作符 命令2 ...
常用的测试操作符
-a或&&:逻辑与,“而且”的意思,前后条件需都成立.
# &&,||操作符能够正常存在于[[]]条件判断结构中,但如果出现在[]结构中,会报错.
-o或||:逻辑或,“或者”的意思,Only one of the pre- and post-conditions needs to hold
!:逻辑否
&&

边栏推荐
猜你喜欢
随机推荐
H5跳转微信公众号解决方案
45.【list链表的应用】
2021GDCPC Guangdong University Student Programming Competition B.Byfibonacci
Detailed operator
递增三元组
2D转换模块&&媒体查询
HF2022-EzPHP reproduction
Apache Doris series: detailed steps for installation and deployment
第十九周进度(了解物联网基础知识)
[MySQL] Related operations on databases and tables in MySQL
2022中国物流产业大会暨企业家高峰论坛在杭州举办!
【LeetCode】42. 接雨水 - Go 语言题解
leetcode 406. Queue Reconstruction by Height
vscode上利用screen命令跑代码
动态修改el-tab-pane 的label(整理)
# # yyds dry goods inventory interview will brush TOP101: to determine whether there is a part of the list
2021GDCPC广东省大学生程序设计竞赛 H.History
In MySQL, the stored procedure cannot realize the problem of migrating and copying the data in the table
HCIP第十六天笔记
【VisDrone数据集】YOLOV3训练VisDrone数据集步骤与结果









![[MySQL] Related operations on databases and tables in MySQL](/img/a5/c92e0404c6a970a62595bc7a3b68cd.gif)