What command can be used to check if a directory exists or not, within a Bash shell script?
You can use test -d (see man test).
-d fileTrue if file exists and is a directory.
For example:
test -d "/etc" && echo Exists || echo Does not exist
Note: The test command is same as conditional expression [ (see: man [), so it's portable across shell scripts.
[- This is a synonym for thetestbuiltin, but the last argument must, be a literal], to match the opening[.
For possible options or further help, check:
help [help testman test or man [