Forward every positional argument received by a wrapper script to run_task.
Preserve arguments containing spaces as separate original arguments.
Which command is appropriate?
A quoted $@ expansion passes each positional argument separately, preserving argument count and boundaries. An unquoted expansion can undergo splitting and glob expansion.
Detailed explanation
run_task $@Incorrect. Unquoted $@ can split words and expand globs, losing original boundaries.
Incorrect. Unquoted $@ can split words and expand globs, losing original boundaries.
run_task "$@"Correct. Passing quoted $@ to run_task forwards each argument independently.
Correct. Passing quoted $@ to run_task forwards each argument independently.
run_task "$*"Incorrect. Quoted $* joins all arguments into one word using the first IFS character.
Incorrect. Quoted $* joins all arguments into one word using the first IFS character.
run_task "$#"Incorrect. $# passes only the argument count.
Incorrect. $# passes only the argument count.
Try it yourself
An example you can run in a temporary verification environment.
sh -c 'show() { printf "%s:<%s>\n" "$#" "$1"; }; show "$@"' wrapper 'two words' secondExpected result
2:<two words>Key points
- Quoted $@ means individual arguments
- It preserves boundaries
- Use it in wrapper scripts
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.