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.
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."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With