[Top][All Lists]

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

Re: Irregularities when using -v, -z, -n

From: Leonid Isaev (ifax)
Subject: Re: Irregularities when using -v, -z, -n
Date: Thu, 29 Jul 2021 12:34:36 +0000
User-agent: Mutt/1.13.4 (2020-02-15)

On Thu, Jul 29, 2021 at 10:27:08AM +0200, wrote:
> I am getting confused with the following code

Well, perhaps you could read "help test"? If you did, you'd see:
   String operators:
      -z STRING      True if string is empty.
      -n STRING      True if string is not empty.
      -v VAR         True if the shell variable VAR is set.
      -R VAR         True if the shell variable VAR is set and is a name


>   [[ -v aa ]] && echo "[[ -v aa ]]: Variable exists."

tests if a variable is set, but

>   [[ -z aa ]] && echo "[[ -z aa ]]: Variable exists, size is zero."

tests that a string "aa" is zero length. You need to replace aa -> "$aa" here.
Also, [[ -z ... ]] returns 0 also for unset variables.

Leonid Isaev

reply via email to

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