help-bash
[Top][All Lists]
Advanced

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

How to test if a variable is declared?


From: Peng Yu
Subject: How to test if a variable is declared?
Date: Thu, 12 Mar 2020 21:58:38 -0500

Hi,

-v only test if a variable has a nonempty value. What is the best way
to test whether a viable is declared? (In the following example, it
should return 0, even the value of x is an empty string.) Thanks.

$ declare x; [[ -v x ]]; echo $?;
1


       -v varname
              True if the shell variable varname is set (has been assigned a
              value).

-- 
Regards,
Peng



reply via email to

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