Probably the simplest approach is to use positional arguments. The shell arranges for each argument passed to your script to appear in a variable, beginning with $1. So, for example, if your script was invoked as:
pkgscript.sh a1 a3
then $1 would have the value "a1" and $2 would have the value "a3". You can iterate over the arguments using a construct such as the following:
while [ ! -z "$1" ]
do
PACKAGE=$1
# perform install command(s) for a single package
shift
done
The key bits here are the test command (abbreviated with the square brackets), the -z option (tests for zero-length string -- i.e., a NULL argument), the shift operator (discards current $1, moves all arguments forward one position), and the while do/done loop. Each of these are discussed in the bash/Bourne shell manual page.
The shell also sets a number of other variables automatically when your script is invoked, including the variable $# (the number of arguments passed to your script). So, for example, you could use this value to determine if your script was invoked with no arguments and print a usage message to inform the user.
You might also want to look at capturing the return code from any installation commands that your script performs, since the user will undoubtedly want to know if the installation was successful.
Hope this helps.
__________________ The slowest component still sits at the keyboard. |