bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Compatible way to test if a variable is set


From: Andrew J. Schorr
Subject: Re: [bug-gawk] Compatible way to test if a variable is set
Date: Tue, 27 Nov 2018 18:21:16 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

On Sun, Nov 25, 2018 at 11:52:03AM -0600, Peng Yu wrote:
> I can use SYMTAB to test if a variable has been set or not. But this
> may not work in other variants of awk (e.g., mawk does not have
> SYMTAB)
> 
> awk -e 'BEGIN { print("foo" in SYMTAB); print "NR" in SYMTAB }'
> 
> Is there a way to test if a variable is set that may be used across
> gawk and other variants (such as mawk)?

What's your actual usage case? If it equals zero and "", it is most
likely undefined, e.g.:

function undef(x) {
   return (x == "") && (x == 0)
}

Regards,
Andy



reply via email to

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