
正文
shell 字符串判空
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
2021-09-01
1. 字符串判空主要用到两个参数
-z判断字符串为空否
-n判断字符串不为空
2. 实例
#!/bin/bashPID=`date`if [ -z "$PID" ]; then
echo "PID is empty"
else
echo "PID is not empty"
fi

#!/bin/bashPID="test"if [ -n "$PID" ]; then
echo "PID is not empty"
fi

3. 补充
在执行脚本时,有时会报错,有时想要知道脚本执行的情况,可以使用以下命令执行脚本
sh -x test.sh

可以清晰地看到脚本执行的过程






