How to check if gcc has failed, returned a warning, or succeeded in Bash?
bash, gcc
Solution
if gcc helloworld.c -o helloworld; then
echo "Success!";
else
echo "Failure";
fi
You want bash to test the return code, not the output. Your code captures stdout, but ignores the value returned by GCC (ie the value returned by main()).
Problem
How would I go about checking whether gcc has succeeded in compiling a program, failed, or succeeded but with a warning? ``` #!/bin/sh string=$(gcc helloworld.c -o helloworld) if [ string -n ]; then echo "Failure" else echo "Success!" fi ``` This only checks whether it has succeeded or (failed or compiled with warnings). -n means "is not null". Thanks! EDIT If it's not clear, this isn't working.