Home > Back-end >  Run a bash for-loop on a stream
Run a bash for-loop on a stream

Time:08-19

I'm using Git Bash for Windows. I want to find every folder named foo and open it in explorer with the command start.

for x in $(find . -name '*foo*' -type d 2> /dev/null); do
  start "$x"
done

I would like the folders to open as they are discovered, as opposed to all at once after the find command is complete. Note that start will open the folder and exit immediately.

How can I treat my find command as a stream and tell bash to run the loop after any new line is printed?

CodePudding user response:

Just use the -exec primary.

find . -name '*foo*' -type d -exec start {} \;
  • Related