Perl and Ruby exit actually exits:
$ perl -e 'BEGIN {print 1; exit}; END {print 2}'
1
$ ruby -e 'BEGIN {print 1; exit}; END {print 2}'
1
Not so for Awk:
$ awk 'BEGIN {print 1; exit}; END {print 2}'
1
2
I tried to solve this with a helper script:"help.awk"
$ cat helper.awk
function really_exit() {
IM_SURE = 1
exit
}
END {
if (IM_SURE) {
exit
}
}
function really_exit() {
IM_SURE = 1
exit
}
END {
if (IM_SURE) {
exit
}
}
but this creates its own problem. If my "normal" script"prog.awk" has only the begin block block:
$ cat normal.awk
BEGIN {
print "test script"
print "script should exit after this prints"
}
BEGIN {
print "start"
}
Then running it:
awk -f helperhelp.awk -f normalprog.awk
will cause it to hang waiting for input. Is a better solution available, for really exiting an Awk script?