Passing Arguments

Arguments can be passed to your script just like regular commands. This makes your scripts much more flexable.

Summary

The $# Variable

The $# variable has the number of arguments passes stored in it.

The $* Variable

The $* variable returns a list of all the arguments.

The $n Variable

The $n variable is used to reference each argument in the order they are given on the commandline. $1 is the first arg, $2 is the second, and so on. For argument higher than 9 you can use curly brackets. For example, the 10th argument is ${10}.

The shift Command

The shift command replaces the value of $1 with $2, $2 with $3, etc.