The positional arguments are --verbose, input.txt, and output.txt.
Consume --verbose so input.txt becomes the new $1.
Which command is appropriate?
shift discards the first positional argument and moves the remaining arguments forward. It is useful for consuming options in an argument parser.
Detailed explanation
unset $1Incorrect. unset does not shift positional arguments and the expansion is not a variable name.
pop $1Incorrect. POSIX sh has no pop builtin for positional arguments.
set $2 $3Incorrect. Rebuilding arguments this way is unsafe and is not the standard one-argument consume operation.
shiftCorrect. shift removes the old $1 and makes the old $2 the new $1.
Try it yourself
An example you can run in a temporary verification environment.
sh -c 'shift; printf "%s|%s|%s\n" "$#" "$1" "$2"' parser --verbose input.txt output.txtExpected result
2|input.txt|output.txtKey points
- shift consumes the first argument
- $# decreases by one
- shift N consumes N arguments
Notes
- Environment: POSIX sh / 短命プロセス
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Shell function
A reusable group of commands that runs in the caller's shell context.
Positional parameter
A numbered argument or special value supplied to a script or function.
Control flow
Conditions, loops, and exit statuses determine which shell commands run.