Reputation: 136
Here's my script:
if [ awk '$0 ~ /Failed/ { print }' $(pwd)/unity.log ]; then
echo "Build Failed"
exit 1
else
echo "Build Success"
exit 0
fi
The gist is that I am checking the file for "Build Failed" message and exiting 1 if failed.
If what I understand is correct, awk
will return blank string if there is no text in the file and some text if it's found. But it shoots syntax error : ./Scripts/build.sh: line 41: [: too many arguments
Upvotes: 1
Views: 2869
Reputation: 43039
Remove the []
, use grep
:
if grep -qw Failed unity.log; then
echo "Build Failed"
exit 1
else
echo "Build Success"
exit 0
fi
Upvotes: 4
Reputation: 95315
You could take advantage of the default exit value being 0. Also, there's no reason to do $(pwd)/filename
; just do filename
.
grep -qw Failed unity.log || { echo "Build Failed"; exit 1; }
echo "Build Success"
It would be also more idiomatic to send the error message on failure to stderr
(with echo >&2
).
Upvotes: 2
Reputation: 1
try this:
if [ ! "$(grep 'Build Failed' unity.log)" ]; then
exit 1
fi
Upvotes: -2