Arguments in bash script
The arguments are stored in variables with a number in the order of the argument starting at 1
- First Argument: $1
- Second Argument: $2
- Third Argument: $3
Example:
./script.bash alpha beta gamma
Variables are: $1=='alpha', $2=='beta' and $3=='gamma'
The variable
$0 is the script name. The total number of arguments is stored in
$#. The variables
$@ (array) and
$* (string) return all the arguments.