Here's a more minimalist solution that will run the test on a single line.
ls $DIR/*/ >/dev/null 2>&1 ; if [ $? == 0 ]; then echo Subdirs else echo No-subdirs fi
By placing / after the wildcard character * , you select only directories, so if there are no directories, then ls returns the error status 2 and prints the message ls: cannot access <dir>/*/: No such file or directory . 2>&1 grabs stderr and passes it to stdout , and then the whole lot gets piped to null (which gets rid of the usual ls output too when there are files).
source share