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

后端 未结 30 2294
猫巷女王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:36

    Use the file program. Considering all directories are also files in Linux, issuing the following command would suffice:

    file $directory_name

    Checking a nonexistent file: file blah

    Output: cannot open 'blah' (No such file or directory)

    Checking an existing directory: file bluh

    Output: bluh: directory

提交回复
热议问题