| -ge | 大于或等于(greater than) |
| -gt | 大于 |
| -eq | 等于(equal) |
| -lt | 小于(less than) |
| -le | 小于等于 |
| -ne | 不等于 |
| -z | 该变量没有长度(无值)就是真,有长度(有值)就是假 |
| -n | 该变量有长度(有值)就是真,无长度(无值)就是假 |
| -f | 文件存在为真 |
| -d | 目录存在为真 |
| -s | 文件存在且非空为真 |
| -w | 文件存在且可写为真 |
| -r | 文件存在且可读为真 |
-z/-n参考Shell 脚本中-z和-n的探讨_Max's code-优快云博客_shell脚本-z
#!/bin/bash
#eg1.
str=
if [ -z "$str" ]
then
echo "str is null"
else
echo "str is $str"
fi
echo str length is ${#str}
#eg1 result is : str is null, and str length is 0
#eg2.
str=123
if [ -n "$str" ]
then
echo "str is $str"
else
echo "str is null"
fi
echo str length is ${#str}
#eg2 result is : str is 123, and str length is 3
825

被折叠的 条评论
为什么被折叠?



