gpt4 book ai didi

linux - 读取 shell 脚本时如何处理未找到的文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:20:45 25 4
gpt4 key购买 nike

我正在通过 shell 脚本从文件中读取一个字符串。它是这样的:

count = 0
while read LINE
do
count++
if [ "$LINE" == "NONE" ]
then
echo "state is NONE"
else
if [ "$LINE" == "PLAYING" ]
then
echo "state is PLAYING"
fi
fi
done<$FILENAME

这是我从文件中读取的内容,以及我如何处理它,如果找不到文件,现在我想做其他事情,有没有办法做到这一点?例如:

if[ file not found]
then
do something
fi

最佳答案

if [ -f path_to_file ]
then
echo "file was found"
else
echo "file was not found"
fi

关于linux - 读取 shell 脚本时如何处理未找到的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15881571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com