1

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.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

5

Don't parse the output of ls.

Instead, use find(1):

find . -type d
Jim L.
  • 7,997
  • 1
  • 13
  • 27