SHIFT(1SH) COMMAND REFERENCE SHIFT(1SH) NAME shift - rename positional parameters (sh built-in) SYNOPSIS shift [ n ] DESCRIPTION The positional parameters from $n+1 . . . are renamed to $1.... If n is not given, it is assumed to be 1. EXAMPLES The major use of shift is to parse command lines. This shell script checks its argument to see if it is a number. If it is, it may be doubled, tripled, or quadrupled by giving the options -d, -t, or -q, respectively, to the shell script. Only the last flag is used. In this case, shift is used so that the argument being worked with is always $1. #!/bin/sh Mult=1 while true do case $1 in -d) Mult=2 ;; -t) Mult=3 ;; -q) Mult=4 ;; -*) echo "$0 : usage : "`basename $0`" [-d] [-t] [-q] num" exit 1 ;; *) break ;; esac shift done if test $# -ne 1 then echo "$0 : usage : "`basename $0`" [-d] [-t] [-q] num" exit 1 Printed 5/12/88 1
SHIFT(1SH) COMMAND REFERENCE SHIFT(1SH) fi if test "0$1" -eq 0 -a "0$1" != "00" then echo "$1 is not a positive integer." exit 1 fi expr "$1" '*' "$Mult" RETURN VALUE [NO_ERRS] Command completed without error. [NP_ERR] An error occurred that was not a system error. Execution terminated. CAVEATS It should be noted that only positional parameters $1 through $9 may be referenced individually. To get the value of $12, shift must be executed three times or with a value of 3, at which point the desired value will be in $9. SEE ALSO break(1sh), cd(1sh), chdir(1sh), continue(1sh), csh(1csh), echo(1sh), eval(1sh), exec(1sh), exit(1sh), export(1sh), hash(1sh), login(1), pwd(1sh), read(1sh), readonly(1sh), return(1sh), set(1sh), sh(1sh), shift(1csh), test(1sh), times(1sh), trap(1sh), type(1sh), ulimit(1sh), umask(1sh), unset(1sh), wait(1sh), which(1sh), and execve(2). Printed 5/12/88 2
%%index%% na:312,122; sy:434,159; de:593,275; ex:868,1451;2703,195; rv:2898,288; ca:3186,377; se:3563,908; %%index%%000000000130