How to check if gcc has failed, returned a warning, or succeeded in Bash?

Your condition should be:

if [ $? -ne 0 ]

GCC will return zero on success, or something else on failure. That line says “if the last command returned something other than zero.”

Leave a Comment