Forrest logo
back to the shift tool

shift:tldr:f0bc3

shift: Move arguments by N places dropping the first N arguments.
$ shift ${N}
try on your machine

The command "shift ${N}" is used in Shell scripting to shift the positional parameters to the left by N positions.

In a Shell script, the positional parameters are the arguments passed to the script when it is executed. By default, the first argument is stored in $1, the second in $2, and so on.

For example, if you have a script named "myscript.sh" and you execute it with three arguments like this:

./myscript.sh arg1 arg2 arg3

Inside the script, you can access these arguments using $1, $2, and $3 respectively.

Now, the "shift" command allows you to move or shift the positional parameters to the left by a specified number of positions. In this case, ${N} represents the number of positions to shift.

So, if you execute the command "shift 2" inside the script, the positional parameters are shifted two positions to the left. The value of $1 becomes "arg2", the value of $2 becomes "arg3", and $3 becomes unset or empty.

This command is primarily used when you want to discard the first few arguments and work with the remaining arguments without changing their respective positions.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the shift tool