To get previous command status in bash use “$?” variable.
echo $? will return zero if previous command is success & if its non zero it indicates failure.
$ ls ; echo $?
Output of the above command is list of files, directories and next line it will return number.
We can use condition for check if previous command is success or failure:
any_command if [ $? -eq 0 ] then echo SUCCESS else echo FAIL fi