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 "help.awk"
function really_exit() {
IM_SURE = 1
exit
}
END {
if (IM_SURE) {
exit
}
}
but this creates its own problem. If "prog.awk" has only the begin block:
BEGIN {
print "start"
}
Then running it:
awk -f help.awk -f prog.awk
will cause it to hang waiting for input. Is a better solution available, for really exiting an Awk script?
BEGINblock be usefully used for both applications with and without input? If not, why not callexitfrom theBEGINblock?exityou can callsystem()and kill theawkprocess directly.ENDblocks are probably executed in the order in which they appear. So if yourBEGINblock callsexitand the firstENDblock (in your helper script) callsexitagain then the "real"ENDblocks should not get executed.awk(1)on my system says exit should "exit immediately" and nothing about going on toENDblocks