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.
Extracting the elusive exit code To display the exit code for the last command you ran on the command line, use the following command: $ echo $? The displayed response contains no pomp or circumstance. It's simply a number.
Exit Codes. Exit codes are a number between 0 and 255, which is returned by any Unix command when it returns control to its parent process. Other numbers can be used, but these are treated modulo 256, so exit -10 is equivalent to exit 246 , and exit 257 is equivalent to exit 1 .
“Normally the exit status is 0 if a line is selected, 1 if no lines were selected, and 2 if an error occurred. However, if the -q or --quiet or --silent is used and a line” You can check if a command is successful or not by using the following syntax. grep -q "Error" test.log.
According to the official Fish documentation, 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With