Use the -d
test to see if the given path is a directory. In that case, -e
will also return true, because that tests for existence of some filesystem object.
To see if a path points to a plain file (no directory, no symlink, no special file), use -f
.
So you want:
-d "$dir/dirname" or next;