如果我们想在Bash中判断一个命令的输出结果是否为空,我们可以使用test命令和-z参数。示例代码如下:

if test -z "$(ls | grep test1.txt)"; then
    echo "The result is empty."
else
    echo "The result is not empty."
fi
 
if test ! -z "$(ls | grep test2.txt)"; then
    echo "The result is not empty."
else
    echo "The result is empty."
fi

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
猜你喜欢
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案