#count dirs in current dir. ex. dir tree: /a/b/c, /a/c/b, /a/d/ dirCount() { echo $(find "$1"* -maxdepth 0 -type d | wc -l); } declare -l _path="/a/" echo $(dirCount "$_path") #outputs: 3