0

I would like to do something like this:

for file in *.sh; do
  echo "$file"
done

But recursively, so something equivalent to this (but this doesn't work):

for file in **/*.sh; do
  echo "$file"
done

Is there a nice and succinct way of doing this? I really like the for x in y syntax.

Is there a nice way of combining this with the find command? I've seen quite a bit of articles using find, but the files where never really looped over in the examples I've found.

Thank you for your time :)

Zhao Li
  • 4,936
  • 8
  • 33
  • 51
  • 1
    What do you get with `**/*.sh`? Perhaps you forgot to add the `shopt -s globstar`. – Socowi Jan 12 '21 at 09:20
  • find , -maxdepth 2 -mindepth 2 -type f – Raman Sailopal Jan 12 '21 at 09:23
  • `globstar` is off by default, since `**` has a defined meaning under POSIX. Deviations from the POSIX standard are typically only used by default when they replace otherwise undefined constructs (like `[[ ... ]]`, array syntax, etc). – chepner Jan 13 '21 at 16:23
  • Thanks for the info. Is there a POSIX equivalent to **? – Zhao Li Jan 13 '21 at 17:05

0 Answers0