Skip to content
The Bash Insectarium

/static/insetario/en/inseto/status/

Menu

BSH-020 · Ghost variables

$?

The last command's exit status: zero is good silence.

Every command ends with a number: zero for success, another value for each species of failure. $? holds the one from the last foreground command.

It is ephemeral — the next command overwrites it, including a curious echo. In scripts it rarely shows: if, && and || read it under the table.

$ grep rainha vazio.txt
$ echo $?
1
$ grep operaria colmeia.txt
operaria: 40 mil por colmeia
$ echo $?
0
One found it, the other did not — and the number tells.