I want to check for the existence of multiple directories, say, dir1
, dir2
and dir3
, in the working directory.
I have the following
if [ -d "$PWD/dir1" ] && [ -d "$PWD/dir2" ] && [ -d "$PWD/dir3" ]; then
echo True
else
echo False
fi
But I suspect there is a more elegant way of doing this. Do not assume that there is a pattern in the names of the directories.
The goal is to check for the existence of a few directories and for the nonexistence of others.
I'm using Bash, but portable code is preferred.
$PWD
, by the way.[ -d "$PWD/dir1"]
is equivalent to[ -d "dir1" ]
. – terdon Mar 02 '19 at 14:43