How do I check if a directory exists in a Bash shell script?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
How do I check if a directory exists in a Bash shell script?
In order to check if a directory exists in Bash using shorter forms, specify the “-d” option in brackets and append the command that you want to run if it succeeds.
Let’s say that you want to check if the “/etc” directory exists for example.
To check if a directory exists in a shell script, you can use the following:
Or to check if a directory doesn’t exist: