1Z0-100 · Question #140
Match the shell variables with their correct description: 1) $1 a) process ID of the shell 1) $* b) the string containing all the arguments to the shell 1) $? c) process ID of the last command run…
The correct answer is A. 1-d, 2-b, 3-e, 4-a, 5-c. See the full explanation below for the reasoning.
Question
Options
- A1-d, 2-b, 3-e, 4-a, 5-c
- B1-b, 2-a, 3-e, 4-d, 5-c
- C1-e, 2-c, 3-a, 4-b, 5-d
- D1-d, 2-a, 3-c, 4-b, 5-e
How the community answered
(25 responses)- A80% (20)
- B4% (1)
- C4% (1)
- D12% (3)
Community Discussion
8The answer is A, and the exam makes this pretty straightforward once you have the mappings memorized: $1 is a positional parameter, $* holds all the arguments as one string, $? gives you the exit status of the last command, $$ is the PID of the shell itself, and $! is the PID of the last background process. Just drill those five and you will not second-guess yourself on test day.
Solid rundown, but if the exam throws a question about $@ versus $*, know that the difference only bites you inside double quotes, where "$@" preserves each argument as a separate word and "$*" collapses them all into one.
A is right. $1 is the classic positional parameter, that one trips nobody up.
I initially leaned toward D because I second-guessed myself on $$ versus $!, but then I mapped each one out: $1 is a positional parameter (d), $* holds all arguments as a string (b), $? is the exit status of the last command (e), $$ is the shell's own process ID (a), and $! is the background process ID (c), which locks in A clean.
$1 as "positional parameter" feels vague but A is the only clean match, go with A.
Agree, and once you see that "positional parameter" is the exact term the bash manual uses, it stops feeling vague and you lock in A without second-guessing.
A is correct, and if you got tripped up it was probably on $$ versus $!, which I have seen people swap on every Solaris shop I ever walked into. $$ is the PID of the shell itself, the thing running your script, and $! is the PID of whatever you last backgrounded with an ampersand, which matters a lot when you are trying to wait on a long-running JVM startup in a boot script. The other temptation is option D, which swaps $$ and $* around, and that gets you if you second-guess yourself and think $$ means "all the stuff" because of the double character. The wording on $* as "the string containing all the arguments" is a little loose since technically $@ and $* behave differently when quoted, but for the purposes of this exam they are treating $* as the catch-all and that is fine, answer A still lines up cleanly with $1 to positional parameter, $* to all arguments, $? to exit status, $$ to shell PID, and $! to background PID.
The $* versus $@ distinction you called "a little loose" is actually the one that bit me hardest on my first attempt, because the exam had a follow-up scenario involving a for loop and quoted expansion, and if you go in thinking they are interchangeable you will pick the wrong variable when IFS splitting matters.