【问题标题】:Check if a file exists in a linux script [duplicate]检查linux脚本中是否存在文件[重复]
【发布时间】:2013-12-07 13:01:24
【问题描述】:

我制作了一个 linux 脚本,它接收一个目录路径作为第一个参数。我不知道路径。我想检查该特定路径是否存在“file.txt”。例如:

if [ -e $1/file.txt ];then
       echo HAHA
fi

【问题讨论】:

  • [[ -f "$1/file.txt" ]] && echo "HAHA" 应该可以工作。
  • 只要$1 不包含任何空格,您所拥有的就应该按预期工作。将其引用为 "$1/file.txt" 可以解决这个问题。

标签: linux bash shell unix


【解决方案1】:
if [[ -e "$1/file.txt" ]]; then
       echo "It exists"
fi

【讨论】:

    猜你喜欢
    • 2012-05-26
    • 1970-01-01
    • 2017-06-14
    • 2019-08-05
    • 1970-01-01
    • 2015-11-06
    • 2012-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多