up vote 0 down vote favorite
share [g+] share [fb]

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?

link|improve this question

feedback

4 Answers

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 '{}' ';'
link|improve this answer
feedback

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"

link|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
feedback

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

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

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.