LX0-104 · Question #5
When the command echo $ outputs 1, which of the following statements is true?
The correct answer is C. It is the exit value of the command executed immediately before echo.. The $? special parameter in shell scripting holds the exit status of the command that was executed most recently in the foreground. If echo $? outputs 1, it indicates that the preceding command terminated with an exit status of 1.
Question
Options
- AIt is the process ID of the echo command.
- BIt is the process ID of the current shell.
- CIt is the exit value of the command executed immediately before echo.
- DIt is the exit value of the echo command.
How the community answered
(40 responses)- A3% (1)
- B5% (2)
- C90% (36)
- D3% (1)
Why each option
The `$?` special parameter in shell scripting holds the exit status of the command that was executed most recently in the foreground. If `echo $?` outputs 1, it indicates that the preceding command terminated with an exit status of 1.
The `$$` special parameter represents the PID of the current shell, not the exit value of any command or the PID of `echo`.
The `$$` special parameter represents the PID of the current shell, not the exit value of any command.
The `$?` special parameter contains the exit status of the last executed foreground command. An output of `1` indicates that the command immediately preceding `echo $?` exited with a non-zero status, typically signifying an error or failure.
The `$?` variable holds the exit status of the *previous* command, not the `echo` command itself. The `echo` command typically exits with `0` unless it encounters an internal error.
Concept tested: Shell special parameters (exit status)
Source: https://www.gnu.org/software/bash/manual/bash.html#Special-Parameters
Topics
Community Discussion
No community discussion yet for this question.