help-bash
[Top][All Lists]
Advanced

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

Irregularities when using -v, -z, -n


From: eduardo-chibas
Subject: Irregularities when using -v, -z, -n
Date: Thu, 29 Jul 2021 15:11:58 +0200

How can I print if some condition is true or false?

Have tried but failed using

  local aa

  echo "local aa"
  p=[[ -v aa ]] ; q=[[ ! -v aa ]]
  echo "[[ -v aa ]] $p [[ ! -v aa ]] $q"
  [[ -v aa ]] && echo "[[ -v aa ]]: Variable exists."
  [[ ! -v aa ]] && echo "[[ ! -v aa ]]: Variable unknown."



> Sent: Friday, July 30, 2021 at 1:04 AM
> From: eduardo-chibas@caramail.com
> To: leonid.isaev@ifax.com
> Cc: help-bash@gnu.org
> Subject: Irregularities when using -v, -z, -n
>
> How does manual never give examples of how to use things !
>
> 6.4 Bash Conditional Expressions
>
> Everyone is expected to figure things out by themselves.
>
>
>
> > Sent: Friday, July 30, 2021 at 12:34 AM
> > From: "Leonid Isaev (ifax)" <leonid.isaev@ifax.com>
> > To: help-bash@gnu.org
> > Subject: Re: Irregularities when using -v, -z, -n
> >
> > On Thu, Jul 29, 2021 at 10:27:08AM +0200, eduardo-chibas@caramail.com wrote:
> > > I am getting confused with the following code
> >
> > Well, perhaps you could read "help test"? If you did, you'd see:
> > -----8<-----
> > ...
> >    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
> >                      reference.
> > ...
> > ----->8-----
> >
> > Therefore,
> >
> > >   [[ -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]