special-parameter

Bash $? — previous exit status

Expands to the exit status of the most recently completed foreground pipeline. Capture it immediately; another completed command can replace it. This is a shell parameter, not a command.

Formal Syntax & Structure

bash syntaxbash
$?

Return Value

string (decimal status)

The expansion produces a decimal status string; expansion itself is not a separate command with a return status.

Working Example

Example Snippetbash
falseprintf '%s\n' "$?"
Bash Reference