bash - Validating return code 0

Hi All, I am trying a script out that will startup on one of my servers. i wanted to check for RC 0 and if it didnt check out, exit.

Typo- This is BASH (Redhat)

This isnt working, and this is the best way to do error checking I feel. Heres my erorr

./start: line 25: syntax error near unexpected token `elif'
./start: line 25: `     elif [ $? -eq 0]'

heres that part of the script. Can this be done differently and more efficiently? Thanks in advance.

echo "$NOW Starting process"
if ps ax | grep -v grep | grep $process > /dev/null
then
    echo "$NOW service is already running"
else
    echo "$NOW  service is not running running, starting.."
    sudo /opt/path/to/code
    echo "$NOW $process service has been started"

    elif [ $? -eq 0]
    then
        echo "$NOW service started successfully!"
    else
        echo "$NOW service did not properly initialize! Exiting"
        exit 1
    fi
fi

I want to say there should be a space before the ]

elif [ $? -eq 0]

Should be:

elif [ $? -eq 0 ]

Also, you cannot use elif without a preceding if statement. Presumably you meant if , rather than elif ?

Plus:

echo "$NOW $process service has been started"

will always give exit status 0 so you cannot test the preceding statement there. You either need to put the exit status in a variable, or put the test right behind the command..