当前位置:网站首页>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
!:逻辑否
&&

边栏推荐
- 阿里云视频点播+项目实战
- HF2022-EzPHP复现
- "Code execution cannot continue because MSVCP140.dll was not found, reinstalling the program may resolve the problem, etc." Solutions
- 牛逼的公司都在用的绩效管理法OKR
- Week 19 Progress (Understanding IoT Basics)
- Necessary artifacts - AKShare quants
- align-content、justify-content、align-items三个属性的作用和效果
- Bugku sql注入
- HF2022-EzPHP reproduction
- Kotlin特殊类
猜你喜欢
随机推荐
【VisDrone数据集】YOLOV3训练VisDrone数据集步骤与结果
Apache Doris series: In-depth understanding of real-time analytical database Apache Doris
# # yyds dry goods inventory interview will brush TOP101: to determine whether there is a part of the list
Chevrolet Trailblazer, the first choice for safety and warmth for your family travel
#yyds干货盘点# 面试必刷TOP101:判断链表中是否有环
ZZULIOJ:1119: sequence order
# Dasctf 7月赋能赛 WP
CPM:A large-scale generative chinese pre-trained lanuage model
#Dasctf July Enabler WP
Compressing Deep Graph Neural Networks via Adversarial Knowledge Distillation
IJCAI2022教程 | 口语语言理解:最新进展和新领域
EasyExcel comprehensive course combat
BFS题单总结
"NIO Cup" 2022 Nioke Summer Multi-School Training Camp 4 DHKLN
[MySQL] DQL related operations
第十九周进度(了解物联网基础知识)
怎么开通代付通道接口?
reindex win10
ZZULIOJ:1120: 最值交换
uni-ui安装