Skip to content
The Bash Insectarium

/static/insetario/en/inseto/shift/

Menu

BSH-028 · Displacements

shift

Discards the first argument and pulls the queue one step forward.

shift throws away $1 and renumbers the rest: $2 becomes $1, $3 becomes $2, and $# shrinks. It is the step of the classic option loop: examine, consume, advance.

With a number, it walks farther: shift 2 consumes two at once. Asking for more than the queue holds fails without touching anything — and $0 watches from outside, unmoved.

$ cat despacha.sh
#!/bin/bash
tarefa=$1; shift
echo "tarefa: $tarefa · alvos: $@"
$ ./despacha.sh polinizar flor1 flor2
tarefa: polinizar · alvos: flor1 flor2
The first in line leaves; the others move up.