On your terminal, type the following command
cal -y 2012
This command would print the calendar for 2012. -y and 2012 are positional parameters. Positional parameters are used to pass arguments to the program. The arguments become available to program as numbered parameters. In the above command, the arguments are passed as follows:
$0 = cal $1 = -y $2 = 2012
Following is an example:
#!/bin/bash #: Title : positional parameters #: Date : 2010-09-22 #: Author : "Nazim Rahman" #: Version : 1.0 #: Description : show how to print and use positional parameters #: Options : war and years #: Example : $ ./upp.sh WWII 1945 printf "Filename: %s\n" "$0" printf "First Argument: %s\n" "$1" printf "Second Argument: %s\n" "$2" printf "%s ended in %s\n" "$1" "$2"
Type the following command to
$ ./upp.sh WWII 1945
Output
Filename: upp.sh First Argument: WWII Second Argument: 1945 WWII ended in 1945