Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

4 Answers 4

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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