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
  • 66,199
  • 35
  • 114
  • 250
  • 2
    Possibly related: [Is there any option with 'ls' command that I see only the directories?](https://unix.stackexchange.com/questions/1645/is-there-any-option-with-ls-command-that-i-see-only-the-directories) – steeldriver May 13 '19 at 22:31

1 Answers1

5

Don't parse the output of ls.

Instead, use find(1):

find . -type d
Jim L.
  • 7,188
  • 1
  • 13
  • 25