Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a directory with a lot of scripts to generate figures. All the scripts match the pattern fig*-gen.sh

I would like to have a bash script (named allfig-gen.sh) to invoke all figure generation scripts. How can I do this?

share|improve this question
up vote 2 down vote accepted

bash internals:

for s in fig*-gen.sh; do
    bash "$s";
done

via (gnu)find:

find . -name "fig*-gen.sh" -exec bash '{}' ';'
share|improve this answer

Unless the scripts require parameters or require to be called in a specific order, you should be able to achieve this via a simple loop

#!/bin/bash

for i in $SCRIPT_DIR/fig*-gen.sh
do
  ./"$i"
done

Caveat: For this to work, the fig*-gen.sh files should specify the interpreter via the #!/bin/bash line. If they do not, you need to invoke the interpreter explicitly by replacing ./"$i" with something like bash ./"$i"

share|improve this answer
    
Also, to use ./"$" as in your example, the files need to have execute permissions enabled, while when using bash ./"$i" they don't. – Dennis Williamson Oct 16 '09 at 10:48

Instead of a for-loop, you can use find:

find $SCRIPT_DIR -type f -name "fig*-gen.sh" -exec {} \;
share|improve this answer

If you want them run in parallel and if you have GNU Parallel http:// www.gnu.org/software/parallel/ installed you can do this:

ls ./fig*-gen.sh | parallel

or even this:

parallel ::: ./fig*-gen.sh

Watch the intro video for GNU Parallel to learn more: http://www.youtube.com/watch?v=OpaiGYxkSuQ

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .