I've been writing bash scripts which perform actions in all the subdirectories in a current directory.
I've implemented this by executing a for loop which recurses over every subdirectory. My question is, how exactly should I obtain the names of the current subdirecties?
What I've been doing is this ...
for SUBDIR in `ls -d /*` ; do
But this sometimes works, sometimes doesn't and I'm sure this isn't best practice.
In the meantime, I've changed to using
for SUBDIR in `find . -maxdepth 1 -mindepth 1 -type d` ; do
Actually, I simply created an alias for this particular find command:
alias subdirs='find . -maxdepth 1 -mindepth 1 -type d'
and then write the for loop with
for SUBDIR in `subdirs` ; do ...
But I want to know what is considered best practice for recursively entering subdirectories and executing commands from within them. Please keep in mind that I really do need to actually cd into each directory to perform the actions from within the subdirectory.
Any and all advice appreciated.