bash if 判断及特殊字符

您所在的位置:网站首页 特殊字符串英文 bash if 判断及特殊字符

bash if 判断及特殊字符

2023-03-14 15:10| 来源: 网络整理| 查看: 265

 bash if 判断

1)字符串判断

str1 = str2     当两个串有相同内容、长度时为真

str1 != str2     当串str1和str2不等时为真

-n str1       当串的长度大于0时为真(串非空)

-z str1       当串的长度为0时为真(空串)

str1        当串str1为非空时为真

2)数字的判断

int1 -eq int2   两数相等为真

int1 -ne int2   两数不等为真

int1 -gt int2    int1大于int2为真

int1 -ge int2   int1大于等于int2为真

int1 -lt int2    int1小于int2为真

int1 -le int2    int1小于等于int2为真 ———————————————— 参考链接:https://blog.csdn.net/weixin_39712969/article/details/111734958

 

OperatorDescription! EXPRESSIONThe EXPRESSION is false.-n STRINGThe length of STRING is greater than zero.-z STRINGThe lengh of STRING is zero (ie it is empty).STRING1 = STRING2STRING1 is equal to STRING2STRING1 != STRING2STRING1 is not equal to STRING2INTEGER1 -eq INTEGER2INTEGER1 is numerically equal to INTEGER2INTEGER1 -gt INTEGER2INTEGER1 is numerically greater than INTEGER2INTEGER1 -lt INTEGER2INTEGER1 is numerically less than INTEGER2-d FILEFILE exists and is a directory.-e FILEFILE exists.-r FILEFILE exists and the read permission is granted.-s FILEFILE exists and it's size is greater than zero (ie. it is not empty).-w FILEFILE exists and the write permission is granted.-x FILEFILE exists and the execute permission is granted. Bash 中常用的特殊字符 “ “ 或者 ' '表示空格。单引号保留字面意思;双引号允许替换。$表示扩展(用于变量、命令替换、算术替换等)\转义字符。用于去除特殊字符的“特殊性”。#评论。不解释此字符之后的任何内容。=任务[ ] 或者 [[ ]]测试; 评估为 true 或 false!否定>>、>、


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3