How to get exit status of program in fish shell

Darc Nawg picture Darc Nawg · Jul 21, 2016 · Viewed 11.6k times · Source

In the bash shell, I could echo $? to get the exit code of a program run on the cli. What is the equivalent in the fish shell? Can't seem to find this in the docs.

Answer

user000001 picture user000001 · Jul 21, 2016

According to this website, https://fishshell.com/docs/current/faq.html#how-do-i-get-the-exit-status-of-a-command, you can use the $status variable:

How do I get the exit status of a command?

Use the $status variable. This replaces the $? variable used in some other shells.