next up previous contents
Next: $#: Number of Parameters Up: Parameters and the Shell Previous: $0: The Name of

$1 $2 $3 ... $9, $*: Shell Parameters

The first parameter to the shell is known as $1, the second as $2, etc. The collection of ALL parameters is known as $*.

Consider the following as an example (file prog):

    #!/bin/sh
    echo the first parameter is $1
    echo the second parameter is $2
    echo the collection of ALL parameters is $*
    exit 0
The output of that program could be:
sh_prompt;SPMgt; prog first second
the first parameter is first
the second parameter is second
the collection of ALL parameters is first second
sh_prompt;SPMgt;

Only nine parameters can be read using the $number scheme. The $* along with the shift instruction is one way to read the remainder of the parameters. Another way is to use the for var in $* command, to be described in the upcoming Control Structures section.



Claude Cantin
Sun Sep 1 02:02:26 EDT 2002