Bash
赵宗义11
邮箱:xinshengzzy@foxmail.com
码云: https://gitee.com/zhao_zong_yi
展开
-
Bash中判断一个命令的输出结果是否为空
如果我们想在Bash中判断一个命令的输出结果是否为空,我们可以使用test命令和-z参数。示例代码如下:if test -z "$(ls | grep test1.txt)"; then echo "The result is empty."else echo "The result is not empty."fiif test ! -z "$(ls | grep te...原创 2019-11-27 20:13:42 · 15847 阅读 · 0 评论 -
在Bash中如何测试一个文件存在或者不存在?
如果我们想测试一个文件temp1是否存在以及另一个文件temp2是否不在在,可以使用以下代码:if test -f "temp1"; then echo "The file temp1 exist!"else echo "The file temp1 doesn't exist!"fiif test ! -f "temp2"; then echo "The file temp2...原创 2019-11-27 11:13:17 · 1077 阅读 · 0 评论