nerdexam
Linux_FoundationLinux_Foundation

LFCS · Question #255

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

The correct answer is A: echo $?. This question asks for the correct Bash command to display the exit status of the previously executed command.

Submitted by yuriko_h· 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

This question asks for the correct Bash command to display the exit status of the previously executed command.

Common mistakes.

  • B. echo $# prints the number of positional parameters passed to a script or function, not the exit status of the last command.
  • C. echo $exit is incorrect because exit is a command used to terminate a shell, not a variable storing the exit status.
  • D. echo $status is not a standard Bash variable for exit status; status is used in some other shells like csh or tcsh.
  • E. echo $&}} is not valid Bash syntax for retrieving the exit status of a command.

Concept tested. Bash exit status variable $?

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

Topics

#Bash shell#Exit status#Special variables#Command line

Community Discussion

No community discussion yet for this question.

Full LFCS PracticeBrowse All LFCS Questions