I’have a bash script calling a jar file like this:
awk -f fileformat.awk list.txt | while read arg1 arg2 arg3 arg4 arg5; do
java -jar /bin/2dbf.jar arg1 arg2 arg3 arg4 arg5
if [[ ${?} -eq 0 ]]; then
echo "2dbf.jar finished at: `date "+%F %T"`"
echo "---------------------------------------------"
else
echo "exiting..."
exit 10
fi
done
the fileformat.awk look like this: if the line starts with # or it does not have 5 fields exit the program.
{
if (NF == 5 && $1 !~ /#.*/) {
print $0
} else {
print "incorrect file format"
"exit 1"
}
}
What I want is that exit 1 in the awk script terminates the whole shell script. but actually it doesn’t and the jar file throws exception because of wrong options.
Because your
exitis in quotes in the AWK program, it is spawning an subshell and exiting from that. And because you’re printing the error message tostdout, that feeds thewhileloop. Change your AWK script to this and it should work: