shift(1) shift(1)
NAME
shift - shift values of positional parameters to the left
SYNOPSIS
shift[ n]
DESCRIPTION
The shell built-in shift shifts the values of positional parameters
over to the left. shift without arguments thus results in the follow-
ing:
- Shell parameter $0 (the command name) is unaffected.
- The original value of $1 is lost; this value can no longer be
accessed.
- Instead, $1 takes the original value of $2, $2 that of $3, and so
on until $8, which takes the value of $9.
- The tenth command-line argument is passed to the last positional
parameter $9.
- $# is reduced by one.
- $* and $@ contain all command-line arguments, starting with the new
value of $1. The original value of $1 is dropped.
By default, the shell provides positional parameters which give you
direct access to only the first nine command-line arguments of a set
command or a shell script. This restriction can be bypassed with
shift, since it allows you to move values over to the left by the
required number of places.
OPERANDS
n A positive integer; shift is executed n times. This means that
positional parameter $1 takes the value of the (n+1)th command
line argument, etc.
If the value of n is too large, shift issues an error message as
soon as no command-line argument is available for $1; i.e. $# is
equal to 0.
n not specified:
shift is executed once.
If $1 already contains the last argument, the next invocation of
shift will result in an error message.
Page 1 Reliant UNIX 5.44 Printed 11/98
shift(1) shift(1)
ERROR MESSAGES
script: cannot shift
This error message is issued when $# is equal to 0, i.e. when no value
could be passed to $1.
LOCALE
The LCMESSAGES environment variable governs the language in which
message texts are displayed. If LCMESSAGES is undefined or is defined
as the null string, it defaults to the value of LANG. If LANG is like-
wise undefined or null, the system acts as if it were not internation-
alized.
The LCALL environment variable governs the entire locale. LCALL
takes precedence over all the other environment variables which affect
internationalization.
EXAMPLES
Example 1
The tenth command-line argument is to be accessed in a shell script:
.
.
arg1=$1
shift
arg10=$9
.
.
.
The original value of $1 is assigned to the arg1 variable. The value
thus remains accessible even after the shift command.
Example 2
The following interactive session demonstrates the changes that take
place in the values of the shell parameters $1, $*, and $# when shift
is invoked:
$ set 1 2 3 4 5 6 7 8 9 10 11 12
$ echo $1
1
$ echo $#
12
$ echo $*
1 2 3 4 5 6 7 8 9 10 11 12
$ shift 6
$ echo $1
7
Page 2 Reliant UNIX 5.44 Printed 11/98
shift(1) shift(1)
$ echo $*
7 8 9 10 11 12
$ echo $#
6
NOTES
Some differences in behavior may occur when using shift, depending on
which shell is being used. The possible differences are not described
specifically.
SEE ALSO
ksh(1), set(1), sh(1).
Page 3 Reliant UNIX 5.44 Printed 11/98