In the Bourne shell (and other shells based on it, such as Bash), the exit status of a command is a number that indicates the success or failure of the command. A exit status of 0
indicates success, while a non-zero exit status indicates failure.
Here are some examples of how to use the exit status in a shell script:
#!/bin/sh # Run a command command # Check the exit status of the command if [ $? -eq 0 ] then echo "Command successful" else echo "Command failed" fi
#!/bin/sh # Run a command command # If the command failed, exit the script with a non-zero exit status if [ $? -ne 0 ] then exit 1 fi # If the command was successful, continue with the rest of the script
#!/bin/sh # Run a command command # Set the exit status of the script to the exit status of the command exit $?
Keep in mind that these are just a few examples.