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.
Incorrect. 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.
Incorrect. 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.
Incorrect. 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.
Correct. 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
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.