I have a bash script that performs makes and then aborts when a make writes to stderr. The code is like this:
make all 2>${ERROR_FILE}
ERR=$(cat ${ERROR_FILE})
if [ ! -z "${ERR}" ];
then
abort "Halted because of errors in make $1: ${ERR}"
fi
However, make writes the f开发者_开发知识库ollowing to the file:
ar: creating ../lib/libmgr.a
ar: creating ../lib/libnet.a
ar: creating ../lib/libeoc.a
ar: creating ../lib/libdvr.a
ar: creating ../lib/libmsg.a
ar: creating ../lib/liblgc.a
ar: creating ../lib/libshm.a
ar: creating ../lib/libsys.a
ar: creating ../lib/librsk.a
ar: creating ../lib/librep.a
ar: creating ../lib/libmdl.a
ar: creating ../lib/libmdb.a
ar: creating ../lib/libdat.a
ar: creating ../lib/libchs.a
What does this mean? Are these errors? If not, why are they written to stderr?
You can use the -c
flag with ar
to suppress the diagnostic message that is written to standard error by default when an archive is created. For example:
$ ar -cruv libfoo.a foo.o bar.o baz.o
They don't look like errors, they look like messages from ar. Why do you stop if the std err file is nonzero? Do you want to stop on warnings too? If not, you may want to stop based on the status of the make command (a non zero $? value after the make command indicates error).
I agree with @skjaidev. Additionally, you can also be more specific about what you are looking for in your ERR variable. One approach is
Edit : changed references from ar to make
make ....
make_rc=$?
case "${ERR}" in
*[Ee][Rr][Rr][Oo][Rr]* )
# real error, modify or duplicate as needed
echo "real error" >&2
exit ${make_rc}
;;
*[Ww][Aa][Rr][Nn]* )
# modify or duplicate as needed for various warning msgs
echo "real warning $(echo "$ERR" | grep -i warn) >&2
# exit ?
;;
* )
# other stuff
;;
esac
I hope this helps.
精彩评论