Bourne/Bash shell special parameters: In POSIX shells, what does the special variable $* expand to during script execution?
-
Aexit status of the last command executed
-
Bprocess ID of the current shell
-
Clist of all positional parameters as a single word
-
Dname of the command (script) being executed
-
ENone of the above
Answer
Correct Answer: list of all positional parameters as a single word
Explanation
Introduction / Context:Shell scripts receive arguments as positional parameters. Special parameters like $, $@, $#, $?, , and $0 provide structured access to arguments, status codes, and process information. Understanding their semantics is critical for writing reliable scripts and interpreting command-line input.
Given Data / Assumptions:
- We are using a Bourne-compatible shell (sh, bash, dash, ksh, zsh in sh mode).
- Double-quoting behavior matters for $* versus $@.
- We need the definition of $* specifically.
Concept / Approach:
$* expands to all positional parameters. When double-quoted, "$*" expands to a single word containing all parameters joined by the first character of IFS (often a space). By contrast, "$@" expands to separate words, one per parameter, preserving argument boundaries. Other parameters serve different roles like exit status ($?), process ID (), and script name ($0).
Step-by-Step Solution:
Recall: $ = all positional parameters in one expansion."$" = one word containing all arguments separated by IFS."$@" = multiple words, one per argument (preferred for safe argument passing).Therefore, select “list of all positional parameters as a single word.”Verification / Alternative check:
In a script invoked as ./s a "b c" d, echo "$" outputs a b c d (one word with embedded spaces as separated by IFS), while echo "$@" outputs a on one field, b c as one field, and d as another, preserving argument boundaries.
Why Other Options Are Wrong:
- Exit status: $? not $.
- Process ID: $$ not $.
- Command name: $0 not $.
- None of the above: Incorrect because the provided definition matches $.
Common Pitfalls:
Using "$" when you intend to forward arguments verbatim; prefer "$@" in that case to preserve argument separation. Be mindful of IFS changes, which alter how "$" joins arguments.
Final Answer:
list of all positional parameters as a single word