Thanks for the note.
Every awk implementation I have tried silently accepts the extra
argument. I think it would break compatibility to turn this warning
on by default, however useful that might otherwise be. Instead,
just run with --lint all the time (set an alias or script). If your
code is clean, you won't get any complaints. :-)
Thanks,
Arnold
Ed Morton <address@hidden> wrote:
I just wrote this code with a bug in it where I used a `,` instead of a
`;` after the printf data argument:
awk -v x=5 '{printf "%s\n", x, x=7}'
My intent was to print a `5` for the first input line and then `7` for
subsequent lines so what I MEANT to write was:
awk -v x=5 '{printf "%s\n", x; x=7}'
Note the semi-colon in `x; x=` vs the comma `x, x=`. I didn't notice the
bug for a while because the code with the bug actually produces the
expected output:
$ seq 3 | awk -v x=5 '{printf "%s\n", x, x=7}'
5
7
7
with no complaints. When I ran with lint enabled I did get a warning:
$ seq 3 | awk --lint -v x=5 '{printf "%s\n", x, x=7}'
awk: cmd. line:1: (FILENAME=- FNR=1) warning: too many arguments
supplied for format string
5
awk: cmd. line:1: (FILENAME=- FNR=2) warning: too many arguments
supplied for format string
7
awk: cmd. line:1: (FILENAME=- FNR=3) warning: too many arguments
supplied for format string
7
So - should that warning appear by default rather than just when
`--lint` is added or is there some scenario where having more arguments
than the format string takes would be deliberate/useful?
I'm running gawk 5.0.1 on cygwin.
Regards,
Ed.