SyntaxFix
Write A Post
Hire A Developer
Questions
Using zsh:
zsh
a=(*(/N)); echo ${#a}
The N is a nullglob, / makes it match directories, # counts. It will neatly cope with spaces in directory names as well as returning 0 if there are no directories.
N
/
#
0