nerdexam
Linux_Foundation

LFCS · 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 shell variable $? stores the exit status (return code) of the most recently executed foreground command.

Submitted by ashley.k· Apr 18, 2026Essential Commands

Question

When the command echo $ outputs 1, which of the following statements is true?

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

(34 responses)
  • A
    3% (1)
  • B
    3% (1)
  • C
    88% (30)
  • D
    6% (2)

Why each option

The special shell variable `$?` stores the exit status (return code) of the most recently executed foreground command.

AIt is the process ID of the echo command.

The `$?` variable does not represent the process ID of any command; `$$` is used for the current shell's PID, and `$!` for the last background command's PID.

BIt is the process ID of the current shell.

The `$?` variable is not used to represent the process ID of the current shell; that is the purpose of the `$$` variable.

CIt is the exit value of the command executed immediately before echo.Correct

The `$?` variable is a special parameter in shell scripting that holds the exit status of the command that was executed immediately before it. A non-zero value like 1 typically indicates that the preceding command encountered an error or a specific condition.

DIt is the exit value of the echo command.

The `$?` variable stores the exit status of the *previous* command, not the `echo` command itself. The `echo` command would generally return 0 upon successful execution.

Concept tested: Shell special variable `$?` (exit status)

Source: https://www.gnu.org/software/bash/manual/bash.html#Special-Parameters

Topics

#Shell variables#Exit status#Command execution

Community Discussion

No community discussion yet for this question.

Full LFCS Practice