Shift is a very useful command in UNIX. You can move the command parameter to the left so that the command parameter position in the script is not changed, and all parameters are traversed in turn.
As Shift 3 indicates that the original $4 now become $ $, the original $ $ now becomes $ $, and so on, the original $, $, $ discard, $ not move. The shift command with no parameters is equivalent to shift 1.
Example: shift_test.sh
#!/bin/SHif[$#-eq0]then Echo"Usage: $ arg1 arg2 ..."Exit1Fiuntil [$#-eq0 ] DoEcho"$*"Echo"First ARG $; Total $#"Shiftdone
Execution Result: $>./shift_test.sh1 2 3 4 51 2 3 4 5First Arg1; Total52 3 4 5First Arg2; Total43 4 5First Arg3; Total34 5First Arg4; Total25First Arg5; Total1
The shift command has another important purpose, and BSH defines 9 positional variables, from $9 to $9, which does not mean that the user can only use the command line with more than 9 parameters, and with the shift command, it is possible to access more than one or more of them.
The shift command moves the number of arguments at a time, specified by the parameters they take. For example, when the shell program finishes processing the first nine command-line arguments, you can use the Shift 9 command to move the $ $ $.
Shell--shift usage