【问题标题】:How to check if file exists but generalized in the middle of a path in a shell script?如何检查文件是否存在但在shell脚本的路径中间概括?
【发布时间】:2018-08-14 00:14:42
【问题描述】:

所以我想以这种方式检查文件是否存在

if [ -e "out/head/tnt-*/output.log" ]
then
    echo "FILE IS THERE"

else
    echo "NOT THERE"
fi

即使文件存在,它也会进入 else 条件,除非我更改

tnt-* to tnt-14

我想保留它 tnt-*,因为对于某些自动化运行,它可能是 tnt-13、tnt-10 或 tnt-14。

有人可以建议另一种在此处检查文件的方法吗?

【问题讨论】:

    标签: linux bash shell find


    【解决方案1】:

    删除引号以启用外壳扩展:

    if [ -e out/head/tnt-*/output.log ]
    then
      echo "FILE IS THERE"
    else
      echo "NOT THERE"
    fi
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 2017-09-11
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多