Bash Script 檔案及目錄是否存在
#!#!/bin/bash if [ -d "/path/to/dir" ]; then # 目錄 /path/to/dir 存在 echo "Directory /path/to/dir exists." else # 目錄 /path/to/dir 不存在 echo "Directory /path/to/dir does not exists." fi 檢查檔案是否存在 #!/bin/bash if [ -f "/path/to/dir/filename" ]; then # 檔案 /path/to/dir/filename 存在 echo "File /path/to/dir/filename exists." else # 檔案 /path/to/dir/filename 不存在 echo "File /path/to/dir/filename does not exists." fi
沒有留言:
張貼留言