Put the scripts you want to run in a directory, and let bash run everything that it finds. Instead of keeping a master list, simply look at the contents of that directory. Here’s a script that will run everything it finds in a directory:
for SCRIPT in /path/to/scripts/dir/* do if [ -f $SCRIPT -a -x $SCRIPT ] then $SCRIPT fi done
We will discuss the
if statement in greater
detail in Chapter 6, but this gives
you a taste. The variable
take on successive values for each file that matches the wildcard
pattern *, which matches everything in the current directory (except
invisible dot files, which begin with a period). If it is a file (the
-f test) and has execute permissions
-x test), the shell will
then try to run that script.
In this simple example, we have provided no way to specify any arguments to the scripts as they are executed. This simple script may work well for your personal needs, but wouldn’t be considered robust; some might consider it downright dangerous. But we hope it gives you an idea of what lies ahead: some programming-language-style scripting capabilities.
Chapter 6 for more about
for loops and