我正在通过 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/