Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get exit status of program in fish shell

Tags:

fish

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.

like image 315
Darc Nawg Avatar asked Jul 21 '16 14:07

Darc Nawg


People also ask

How do I get exit status from last command?

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.

What is exit code in shell script?

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 .

What is exit 1 and exit 2 in shell script?

“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.


1 Answers

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.

like image 88
user000001 Avatar answered Sep 26 '22 00:09

user000001