I need to have files from many directories in a for loop. As for now, I have the following code:
for f in ./test1/*;
...
for f in ./test2/*;
...
for f in ./test3/*;
...
In each loop I'm doing the same thing. Is there a way to get files from multiple folders?
Thanks in advance
You can give multiple "words" to
for
, so the simplest answer is:There are then various tricks to reduce the amount of typing; namely globbing and brace expansion.
Try
for f in ./{test1,test2,test3}/*
orfor f in ./*/*
depending on what you want.