shift
shell builtinLinux/Unix
The shift command is one of the most frequently used commands in Linux/Unix-like operating systems. shift Shift positional parameters in a shell script
Quick Reference
Command Name:
shift
Category:
shell builtin
Platform:
Linux/Unix
Basic Usage:
shift [options] [arguments]
Common Use Cases
Syntax
shift [n]
Options
Option | Description |
---|---|
n |
Optional numeric argument specifying the number of positions to shift (default is 1) |
Examples
How to Use These Examples
The examples below show common ways to use the shift
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
Remove the first positional parameter and shift all others down
shift
Remove the first 2 positional parameters and shift all others down
shift 2
Advanced Examples:
# Process all arguments in a loop while [ $# -gt 0 ]; do echo "Processing: $1" shift doneProcess remaining arguments
for arg in "$@"; do