bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Is there a way to automatically let gawk fail when an ini


From: Peng Yu
Subject: Re: [bug-gawk] Is there a way to automatically let gawk fail when an initialized variable is used?
Date: Thu, 29 Nov 2018 04:35:13 -0600

On Thu, Nov 29, 2018 at 1:41 AM <address@hidden> wrote:
>
> Peng Yu <address@hidden> wrote:
>
> > Hi,
> >
> > In certain cases, it may be useful to let gawk fail when an
> > initialized variable is used. Of course, one can use if to test, but
> > it can be cumbersome. Is there a way to do so automatically in gawk?
> > Thanks.
> >
> > awk 'BEGIN { print typeof(x) }'
>
> I assume you mean "uninitialized". This is what --lint is for:
>
>         $ ./gawk --lint 'BEGIN { print typeof(x) }'
>         gawk: cmd. line:1: warning: `typeof' is a gawk extension
>         gawk: cmd. line:1: warning: reference to uninitialized variable `x'
>         untyped

This one still goes on to run the program.

> If you want fatal errors:
>
>         $ ./gawk --lint=fatal 'BEGIN { print x }'
>         gawk: cmd. line:1: fatal: reference to uninitialized variable `x'

It doesn't just give errors for uninitialized variables. It gives out
messages for other things as well. A way to just deal with the
uninitialized variables would be appreciated.

echo 1 | awk -L fatal -e 'function f(x) { print x; x=2 } { x=$1; f(x);
print x }'
awk: cmd. line:1: warning: function `f': parameter `x' shadows global variable
awk: cmd. line:1: fatal: there were shadowed variables.

-- 
Regards,
Peng



reply via email to

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