nerdexam
Linux_Foundation

LFCS · Question #255

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

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 $&}

How the community answered

(31 responses)
  • A
    87% (27)
  • B
    3% (1)
  • C
    3% (1)
  • D
    6% (2)

Why each option

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

Aecho $?Correct

In Bash, the special parameter `$?` holds the exit status of the last executed foreground command. An exit status of `0` generally indicates success, while any non-zero value signifies an error or abnormal termination, making `echo $?` the correct way to display it.

Becho $#

`echo $#` prints the number of positional parameters passed to a script or function, not the exit status of the last command.

Cecho $exit

`echo $exit` is incorrect because `exit` is a command used to terminate a shell, not a variable storing the exit status.

Decho $status

`echo $status` is not a standard Bash variable for exit status; `status` is used in some other shells like `csh` or `tcsh`.

Eecho $&}

`echo $&}}` is not valid Bash syntax for retrieving the exit status of a command.

Concept tested: Bash exit status variable `$?`

Source: 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 Practice