shell script 檢查檔案是否存在 - mintrabbitplus
Site icon mintrabbitplus

shell script 檢查檔案是否存在

使用test指令:

if test -e /path/to/file; then
  echo "文件存在"
else
  echo "文件不存在"
fi

或者

if [ -e /path/to/file ]; then
  echo "文件存在"
else
  echo "文件不存在"
fi

除了-e選項,還可以使用以下選項來測試檔案的屬性:

Exit mobile version