[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] gawk 4.1.3 gensub() warning
From: |
Ed Morton |
Subject: |
Re: [bug-gawk] gawk 4.1.3 gensub() warning |
Date: |
Thu, 3 Sep 2015 21:05:56 -0500 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 |
see my response below
On 9/3/2015 7:34 AM, address@hidden wrote:
Ed Morton <address@hidden> wrote:
I'm seeing this new warning in gawk 4.1.3 executing existing scripts:
$ echo 'a' | gawk '{print gensub(/a/,"b","")}'
gawk: cmd. line:1: (FILENAME=- FNR=1) warning: gensub: third argument `' treated
as 1
b
This will impact a ton of scripts, like if sed suddenly started issuing warnings
if you wrote `s/foo/bar/` instead of `s/foo/bar/1`. Is it here to stay?
Ed.
The warning is indeed here to stay. Use of "" is wrong; you should
supply a numeric 1 there. Fix your scripts.
Arnold
Arnold - there's lots of things that are "wrong" but harmless so gawk just
handles them sensibly without issuing warnings. For example, using an out of
range starting index for substr():
$ awk 'BEGIN{print substr("foobar",-127,3)}'
foo
$ awk 'BEGIN{print substr("foobar","",3)}'
foo
is IMHO much more likely to indicate a real problem in your code than using ""
instead of 1 in gensub() but in substr() gawk just quietly assumes you meant to
use 1 instead of -127 or "" or whatever value a loop variable accidentally
became. If substr() can continue to quietly assume that anything numerically
less than 1 means 1, why can't gensub() continue to do that too after all of
these years of doing so?
Anyway, I've changed 130+ scripts on one machine now, hoping I didn't screw any
of them up, and moving on to my next machine so I'm far enough along the process
of updating my scripts that I'll finish the rest and so I'm fine either way.
Thanks for the quick response.
Ed.