bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gawk skipping ./file name containing =


From: Nethox
Subject: Re: gawk skipping ./file name containing =
Date: Thu, 7 Oct 2021 15:12:23 +0200

2021-10-03T12:55:11-05:00, Ed Morton <mortoneccc@comcast.net>:
> On 10/3/2021 12:41 PM, Davide Brini wrote:
> > On Sun, 3 Oct 2021 19:26:29 +0200, Davide Brini <dave_br@gmx.com> wrote:
> >
> >> Doesn't seem to be related to the filenames though, I see the same output
> >> with a file named "foo":
> >
> Ah, you're right on both counts. It's not the `=` in the file name
> that's the issue, it's that I should have done:
>
>     printf ... | awk 'script' -
>
> (with `-` on the end) so that I started populating ARGV[] at ARGV[2]
> instead of ARGV[1] since ARGV[1] was already consumed when the `NR==FNR`
> block was being interpreted.

The implicit "-" AKA stdin is included in the traversal, but not in
ARGV/ARGC because it is not strictly an argument. It is tricky but
expected behaviour AFAIK. Gawk and BWK awk require the explicit "-"
workaround, mawk does not.


However, there is another related issue with gawk-specific ARGIND
when a file argument is not passed.

Explicit read from "-" is correct:
$ gawk '{ print ARGIND }' - <<<Lorem
1
$ gawk '{ print ARGIND }' x=xxx - <<<Lorem
2
$ gawk '{ print ARGIND }' '' x=xxx - <<<Lorem
3

But implicit read from "-" looks wrong:
$ gawk '{ print ARGIND }' <<<Lorem
0    <-- Expected 1. That would make ARGV[1] == ARGV[ARGC] == ""
    (typeof unassigned), which is technically correct and better
    than ARGV[0] == "gawk".
$ gawk '{ print ARGIND }' x=xxx <<<Lorem
1    <-- Expected 2.
$ gawk '{ print ARGIND }' x=xxx '' y=yyy '' '' <<<Lorem
3    <-- Expected 6.

As for the documentation, section 2.3 of the Texinfo manual:
> As each element of ARGV is processed, gawk sets ARGIND to the
> index in ARGV of the current element.
With gawk 5.1.1f this is not always true, as shown. Furthermore,
section 7.5.2 and the man page just talk about "files" instead of
"arguments" (files, assignments, or empty strings), which is
misleading.

Regards.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]