|
From: | Ed Morton |
Subject: | Should nextfile in BEGINFILE skip ENDFILE? |
Date: | Sat, 14 Nov 2020 08:12:25 -0600 |
User-agent: | Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 |
In |gawk|, execution of |nextfile| causes additional things to happen: any |ENDFILE| rules are executed **if |gawk| is not currently in an |END| or |BEGINFILE| rule**, |ARGIND| is incremented, and any |BEGINFILE| rules are executed. (|ARGIND| hasn’t been introduced yet. See section Predefined Variables <https://www.gnu.org/software/gawk/manual/gawk.html#Built_002din-Variables>.)With |gawk|, |nextfile| is useful inside a |BEGINFILE| rule to skip over a file that would otherwise cause |gawk| to exit with a fatal error. In this case, **|ENDFILE| rules are not executed**.
which seems to be clearly saying that when you call `nextfile` inside a `BEGINFILE` block the `ENDFILE` block isn't executed and yet when I do that in gawk 5.1.0 on cygwin I see it is:
$ awk 'BEGINFILE{print "a"; nextfile} ENDFILE{print "b"}' /dev/null a b Is that a bug or a documentation issue? Ed.
[Prev in Thread] | Current Thread | [Next in Thread] |