<tt>shift</tt>: Shifts Parameters



next up previous contents
Next: read: Reading Input Up: Parameters and the Previous: $#: Number of

shift: Shifts Parameters

When a large number of parameters (> 9) are passed to the shell, shift can be used to read those parameters. If the number of parameters to be read is known, say three, a program similar to the following could be written:

    #!/bin/sh
    echo The first parameter is $1.
    shift
    echo The second parameter is $1.
    shift
    echo The third parameter is $1.
    exit 0

Obviously the above example contains redundancy, especially if there are a large number of parameters.

To solve this problem: use a for or while loop.



Super-User
Fri Feb 17 15:55:40 EST 1995