如何检查gcc是否失败,返回警告或在Bash中成功? [英] How to check if gcc has failed, returned a warning, or succeeded in Bash?
本文介绍了如何检查gcc是否失败,返回警告或在Bash中成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查gcc是否已成功编译程序,失败或成功但发出警告?
#!/ bin / sh
string = $(gcc helloworld.c -o helloworld)
if [string -n];那么
回声失败
其他
回声成功!
fi
这只会检查它是否成功或(失败或编译时有警告)。
-n表示不为空。
谢谢!
编辑如果不清楚,这是行不通的。
解决方案
如果gcc helloworld.c -o helloworld;那么
会回显成功!;
else
echo失败;
fi
您希望bash测试返回代码,而不是输出。您的代码会捕获stdout,但会忽略GCC返回的值(即main()返回的值)。
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.
解决方案
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()).
这篇关于如何检查gcc是否失败,返回警告或在Bash中成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文