shift builtin

The builtin that drops $1 and moves every remaining positional parameter down by one, lowering $# as well.

In more detail

A while loop that handles $1 and then shifts walks through all the arguments. After getopts, shift "$((OPTIND - 1))" removes the options so only the operands remain.

Example

while [ "$#" -gt 0 ]; do echo "$1"; shift; done

Related terms

Taught in

References