How can I check if a directory exists in a Bash shell script?

后端 未结 30 2481
猫巷女王i
猫巷女王i 2020-11-22 10:35

What command can be used to check if a directory exists or not, within a Bash shell script?

30条回答
  •  佛祖请我去吃肉
    2020-11-22 11:34

    I find the double-bracket version of test makes writing logic tests more natural:

    if [[ -d "${DIRECTORY}" && ! -L "${DIRECTORY}" ]] ; then
        echo "It's a bona-fide directory"
    fi
    

提交回复
热议问题