在shell中可以使用-e參數來判斷文件是否存在。具體命令如下:
-e
if [ -e file.txt ]; then echo "File exists" else echo "File not found" fi
其中file.txt為要判斷的文件名。如果文件存在,則會輸出"File exists";如果文件不存在,則會輸出"File not found"。
file.txt