Thursday, July 17, 2014

Exit status in linux shell and grep ( $? )

I hope we all are using exit status in shell scripting mostly for decision making. The interesting thing we only check exit status 0 or non zero. But when I made an analysis ( got into one mistake also ;) ) there are some exit status with valid reason.

After a command execution we are using $? for getting exit status in shell. If it returns 0 it means the command which had given executed successfully. But if something went wrong in the command execution?? we will get a non zero value as exit status. Here are the list of exit status.'

1 means general errors. 2 for misuse of shell builtins.  126 cannot invoke requested command. 127 Command not found. 128 Invalid arugment to exit. and  130  termination with Ctrl + C.






If you see the usage of grep it return 0 if the selected lines are found and 1 for not found. Grep returns 2 for general errors.
.

No comments:

Post a Comment

Which operating system you like most?