Bash: find a script in any sub-folder and execute it

Spread the word!

Motivation

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

Note:

  • 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.

Be the first to comment

Leave a Reply

Your email address will not be published.


*