Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The most basic method of passing data to your shell script is to use command line parameters. Command line parameters allow you to add data values to the command line when you execute the script:
$ ./addem 10 30
This example passes two command line parameters (10 and 30) to the script addem. The script handles the command line parameters using special variables. The following sections describe how to use command line parameters in your bash shell scripts.
Reading Parameters
The bash shell assigns special variables, called positional parameters, to all of the parameters entered in a command line. This even includes the name of the program the shell executes. The positional parameter variables are standard numbers, with $0 being the name of the program, $1 being the first parameter, $2 being the second parameter, and so on, up to $9 for the ninth parameter.