shift

Move position parameters.

Summary

shift[n]

The main purpose

Parameters

n (optional): an integer greater than or equal to 1 and less than or equal to the number of parameters. The default is 1.

return value

Returns successful unless n is greater than the number of parameters or n is less than 1 or other illegal values.

example

Assume our script file (test.sh) is as follows:

#!/usr/bin/env bash
# Display the first three positional parameters.
echo "$1 $2 $3"
# Remove the first two positional parameters and rename $3 to $1, and so on.
shift 2
echo "$1 $2 $3"

Execute this script in the terminal:

sh test.sh q w e r t

The return information is as follows:

q w e
e r t

Notice