Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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*

I would like to have a bash script (named 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*; do
    bash "$s";

via (gnu)find:

find . -name "fig*" -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


for i in $SCRIPT_DIR/fig*

Caveat: For this to work, the fig* 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*" -exec {} \;
share|improve this answer

If you want them run in parallel and if you have GNU Parallel http:// installed you can do this:

ls ./fig* | parallel

or even this:

parallel ::: ./fig*

Watch the intro video for GNU Parallel to learn more:

share|improve this answer

Your Answer


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.