builtin

Bash shift — consume positional arguments

Removes n positional parameters (default one) and renumbers those remaining. Fails when n is negative or exceeds the count. Does not shift $0.

Formal Syntax & Structure

bash syntaxbash
shift [n]

Parameters & Attributes

NameTypeDescription
nintegerNumber of parameters to remove.

Return Value

exit status

Zero on success, nonzero if invalid or out of range.

Working Example

Example Snippetbash
bash -c 'printf "%s\n" "$1"; shift; printf "next=%s count=%s\n" "$1" "$#"' demo alpha beta gamma
Bash Reference