Anyone knows what $? means in BASH?
I have to write a script that restarts a process if it crashes or is killed. So I found this to start from :
RESTART="/etc/init.d/apache2 restart"
if [ $? -ne 0 ] # if apache not running
then
# restart apache
$RESTART
fi
I have done a search, but $? eludes me.
I am not sure if the above script is the best way to do this, I am assuming that $RESTART will hang until the process is killed or dies? If not, I would assume there would be some kind of sleep() call in there so this thing doesn;t spin at 1000 miles per hour.
It’s the exit status of the most recently executed command.
Look it up at tldp.