Sunday, September 07, 2008

Exit Status - Shell script

Whenever a shell script is executed it checks the exit status
of command to verify if it executed sucessfully.

True = 0
False = Non Zero Value

You can check exit status value as below:

Eg:

#!/bin/bash

echo hello
echo $?
# Exit status 0 returned because command executed successfully.

lskdf
Unrecognized command.
echo $? # Non-zero exit status returned because command failed to execute.

$./script.sh

hello
0

./script.sh line 5 lskdf command not found.
127

No comments: