nerdexam
CompTIA

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.

Shells, Scripting and Data Management

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

(40 responses)
  • A
    3% (1)
  • B
    5% (2)
  • C
    90% (36)
  • D
    3% (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.

AIt is the process ID of the echo command.

The `$$` special parameter represents the PID of the current shell, not the exit value of any command or the PID of `echo`.

BIt is the process ID of the current shell.

The `$$` special parameter represents the PID of the current shell, not the exit value of any command.

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

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.

DIt is the exit value of the echo command.

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

#shell variables#exit status#bash features

Community Discussion

No community discussion yet for this question.

Full LX0-104 Practice