Sometimes you need to check if the command you have fired is executed successfully or not in Linux shell.
This can be achieved by using echo command.
Quote:
#!/bin/bash
COMMAND_1
. . .
COMMAND_LAST
# Will exit with status of last command.
exit $?
|
$? reads the exit status of the last command executed. After a function returns, $? gives the exit status of the last command executed in the function. This is Bash's way of giving functions a "return value."
Following the execution of a pipe, a $? gives the exit status of the last command executed.
After a script terminates, a $? from the command-line gives the exit status of the script, that is, the last command executed in the script, which is, by convention, 0 on success or an integer in the range 1 - 255 on error.
Hope this helps !