什么命令检查Bash shell脚本中是否存在目录?
当前回答
if [ -d "$Directory" -a -w "$Directory" ]
then
#Statements
fi
上述代码检查目录是否存在以及是否可写。
其他回答
一个衬垫:
[[ -d $Directory ]] && echo true
[[ -d "$DIR" && ! -L "$DIR" ]] && echo "It's a directory and not a symbolic link"
注:引用变量是一种很好的做法。
说明:
-d: 检查是否是目录-五十: 检查是否是符号链接
可以使用以下发现,
find . -type d -name dirname -prune -print
file="foo"
if [[ -e "$file" ]]; then echo "File Exists"; fi;
使用-e检查将检查文件,其中包括目录。
if [ -e ${FILE_PATH_AND_NAME} ]
then
echo "The file or directory exists."
fi