nerdexam
Linux_FoundationLinux_Foundation

LFCS · Question #538

LFCS Question #538: Real Exam Question with Answer & Explanation

The correct answer is A: echo $?. The special shell variable $? in bash holds the exit status of the most recently executed foreground command.

Submitted by zhang_li· Apr 18, 2026Essential Commands

Question

Which of the following commands will print the exit value of the previous command to the screen in bash?

Options

  • Aecho $?
  • Becho $#
  • Cecho $exit
  • Decho $status
  • Eecho $&}

Explanation

The special shell variable $? in bash holds the exit status of the most recently executed foreground command.

Common mistakes.

  • B. $# expands to the number of positional parameters (arguments) passed to a script or function, not the exit status of the last command.
  • C. $exit is not a standard bash variable that stores the exit status of the previous command; this variable name is not recognized by bash for this purpose.
  • D. $status is not a standard bash variable for the exit status; it is typically used in other shells like csh or tcsh but not bash.
  • E. $&}} is syntactically incorrect and not a valid bash variable for accessing the exit status of the previous command.

Concept tested. Bash special parameter $?

Reference. https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Special-Parameters

Topics

#shell variables#exit codes#bash#command-line

Community Discussion

No community discussion yet for this question.

Full LFCS PracticeBrowse All LFCS Questions