The return value of any bash command is stored in $?. If its value is 0, it means the command executed successfully; otherwise, there was some error in execution.
Here is an example. I am running my SQL queries in this example.
psql -d dbname -f myqueries.sqlif [ $? -eq 0 ]; then echo "SQL finished"else echo "SQL failed" exit 1fi