Type the special parameter, including its leading dollar sign, that expands to the exit status of the most recently completed foreground command.
LPIC-1 Exam 102-500, objective 105. Shells and shell scripting easy
Draft — not checked yet. This question was written from the published exam objectives and cites the clause it comes from, but nobody has yet read it against that clause and signed for it.
It is kept out of search results and out of mock exams until they have. Read the source below before you take the answer as settled.
Answer
Type the answer.
Accepted answer
$?
Case sensitive — Linux is, and grading LS as ls would teach a falsehood.
Why
$? holds the exit status of the last foreground command: 0 for success, non-zero for failure. It is overwritten by the very next command, including by an `echo`, so capture it at once with something like `status=$?` if you need it twice. Related parameters: $$ is the shell's own PID, $! the PID of the last background job, $0 the name the script was invoked as, and $# the number of positional parameters.
Where this comes from
- Cited
- LPI exam objective 105.2
- What it says
- Read the exit status of the previous command.
Practise this
Reading one question is not practice. The trainer will draw a set from objective 105 and space the ones you get wrong.