I am trying to make a BASH script to test the files in the working directory and return the files that are directory files.

One approach that I can think of is, starting with ls and feeding the output into test -d.

I'm not sure what sort of looping would be best for testing each variable. And, how I can design the loop so that it can handle an unlimited amount of input from ls, not just designed for a maximum of say 20 variables.


1 Answer 1


Don't parse the output of ls.

Instead, use find(1):

find . -type d

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .