Question 140
A command just ended and a technician wants the numeric exit status of that command. One student proposes Run echo $? immediately after the command and another proposes Run hash -r in Bash. Which technical comparison is the soundest?
Explanation
Correct Answer
Correct distinction: Run echo $? immediately after the command targets last exit code inspection; The special parameter $? expands to the most recently completed foreground command's exit status. The compared alternative instead serves Bash command lookup refresh.
Incorrect Answers
Incorrect mapping: Run hash -r in Bash is used for Bash command lookup refresh. It does not displace Run echo $? immediately after the command for the described requirement.
The mechanisms are different: The special parameter $? expands to the most recently completed foreground command's exit status. By contrast, hash -r clears Bash's remembered executable path locations for future lookup. They are not universally interchangeable.
The third option addresses Bash variable expansion: Double-quoted parameter expansion replaces $name with its value while preserving it as one argument. The original action remains relevant because The special parameter $? expands to the most recently completed foreground command's exit status.