shell 如何通过Bash脚本检查文件是否存在?

ztigrdn8  于 2023-02-05  发布在  Shell
关注(0)|答案(2)|浏览(239)

我试图克隆一个repo,并在通过bash脚本完成后测试它。我已经基于Bash Shell: Check File Exists or Not编写了测试代码。

#!/bin/bash

echo "*** TRY TO INIT INFER ***"

# Clone Infer
INFER_GIT_PATH="https://github.com/facebook/infer.git"
echo "> Try to Clone Infer from ${INFER_GIT_PATH}"
git clone ${INFER_GIT_PATH}

INFER_PATH="/infer/infer/bin/infer"
[ -e ${INFER_PATH} ] && echo "Infer downloaded successfully" || echo "Something went wrong :("

虽然repo可以成功下载并且/infer/infer/bin/infer.sh存在,但我总是收到Something went wrong :(消息。

rjjhvcjd

rjjhvcjd1#

将其更改为(使用相对路径):

INFER_PATH="./infer/infer/bin/infer"
[ -e ${INFER_PATH} ] && echo "Infer downloaded successfully" || echo "Something went wrong :("

应该会有用的。

3b6akqbq

3b6akqbq2#

如果你想知道一个文件是否存在,你可以使用-f标志:

[ -f /infer/infer/bin/infer ] && echo "Infer downloaded successfully" || echo "Something went wrong :("

相关问题