Monday, January 28, 2019

BASH Script

BASH Script

1. Meaning of exit 0, exit 1 and exit 2 in a bash script

Exit code 0 - Success
Exit code 1 - General errors, Miscellaneous errors, such as "divide by zero" and other impermissible operations
Exit code 2 - Misuse of shell builtins (according to Bash documentation) 
Example: empty_function() {}


$?       Expands to the exit status of the most recently executed foreground pipeline.
echo $? - Gives the EXIT STATUS of the most recently executed command . This EXIT STATUS would most probably be a number with ZERO implying Success and any NON-ZERO value indicating Failure
? - This is one special parameter/variable in bash.
$? - It gives the value stored in the variable "?".
Some similar special parameters in BASH are 1,2,*,# ( Normally seen in echo command as $1 ,$2 , $* , $# , etc., ) .

0 implies true 1 implies false

No comments:

Post a Comment

  How to Change Instance Type & Security Group of EC2 in AWS By David Taylor Updated April 29, 2023 EC2 stands for Elastic Compute Cloud...