[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
too many arguments lint warning - should it be standard?
From: |
Ed Morton |
Subject: |
too many arguments lint warning - should it be standard? |
Date: |
Mon, 17 Feb 2020 12:10:57 -0600 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 |
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.
- too many arguments lint warning - should it be standard?,
Ed Morton <=