This code recursively search for a script called “myScript.sh” in every sub folders and run it, ignoring any match inside paths containing “IgnoreMe“.
Bash (Linux) Script
find "$(pwd)" -type f -not -path "*IgnoreMe*" -name 'myScript.sh' | xargs -I % sh -c 'cd $(dirname %) && ./myScript.sh'
- xargs is used to forward previous command outputs (before the pipe | ) individually as input arguments to the next command.
- COMMAND1 | xargs -I % COMMAND2 : each output from COMMAND1 is taken and assigned to the character % (you could choose any other character) in such a way that whenever it’s found inside COMMAND2 it will be replaced by the COMMAND1‘s output.