Location parameters can be usedShift command shifts left. For exampleShift 3 indicates the original$4 now becomes$1, the original$5 now becomes$2, etc. The original$1,$2,$3 discard,$0 is not moved. Without ParametersThe shift command is equivalentshift 1。
Very useful Unix Command: shift. We know that the number of location variables or command line parameters must be fixed, or when the Shell program does not know the number, all parameters can be assigned to the variable $ * together *. If you want Shell to process parameters one by one without knowing the number of location variables, that is, after $1, after $2, it is $3. The value of $1 before the shift command is executed is not available after the shift command is executed.
The test command is as follows:
Root @ wl-MS-7673:/home/wl/desktop/shell # cat-n test. sh 1 # shift command (x_shift.sh) 2 until [$ #-eq 0] 3do 4 echo "the first parameter is: $1. The number of parameters is: $ #"5 shift 6doneroot @ wl-MS-7673:/home/wl/desktop/shell #
The output result is as follows:
Root @ wl-MS-7673:/home/wl/desktop/shell # chmod u + x test. sh root @ wl-MS-7673:/home/wl/desktop/shell #. /test. sh a B c d e f g the first parameter is: a parameter number: 7 the first parameter is: B parameter number: 6 the first parameter is: c parameter number is: 5. The first parameter is: d. The number of parameters is: 4. The first parameter is: e. The number of parameters is: 3. The first parameter is: f. The number of parameters is: 2. The first parameter is: g parameter number: 1root @ wl-MS-7673:/home/wl/desktop/shell #