bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] How to test if a variable is uninitialized or is just a v


From: Davide Brini
Subject: Re: [bug-gawk] How to test if a variable is uninitialized or is just a variable that happens to be an empty string?
Date: Tue, 09 Oct 2012 09:53:40 +0200

(sorry for top-posting)

Given awk's definition of "uninitialized variable", I think this could work:

if ((var == 0) && (var == "")) { print "uninitialized" }



Peng Yu <address@hidden> wrote:


Hi,

I'm not able to find a function to test if a variable is uninitialized
or is just a variable that happens to be an empty string in the
manual. Is there such a function in awk? Thanks!

~/linux/test/awk/lang/variable/undefined$ cat main.sh
#!/usr/bin/env bash

echo | awk 'BEGIN{print "^" x "$"}'
echo | awk 'BEGIN{if(x=="") { print "Hello World!" }}'
echo | awk 'BEGIN{x=""; if(x=="") { print "Hello World!" }}'

--
Regards,
Peng


reply via email to

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