How to check if gcc has failed, returned a warning, or succeeded in Bash?
To tell the difference between compiling completely cleanly and compiling with errors, first compile normally and test $?. If non-zero, compiling failed. Next, compile with the -Werror (warnings are treated as errors) option. Test $? - if 0, it compiled without warnings. If non-zero, it compiled with warnings.
Ex:
gcc -Wall -o foo foo.cif [ $? -ne 0 ]then echo "Compile failed!" exit 1figcc -Wall -Werror -o foo foo.cif [ $? -ne 0 ]then echo "Compile succeeded, but with warnings" exit 2else echo "Compile succeeded without warnings"fi