[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, 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
- Irregularities when using -v, -z, -n, eduardo-chibas, 2021/07/29
- Re: Irregularities when using -v, -z, -n,
Leonid Isaev (ifax) <=
- Irregularities when using -v, -z, -n, eduardo-chibas, 2021/07/29
- Irregularities when using -v, -z, -n, eduardo-chibas, 2021/07/29
- Re: Irregularities when using -v, -z, -n, Alex fxmbsw7 Ratchev, 2021/07/29
- Re: Irregularities when using -v, -z, -n, Alex fxmbsw7 Ratchev, 2021/07/29
- Re: Irregularities when using -v, -z, -n, Leonid Isaev (ifax), 2021/07/29
- Irregularities when using -v, -z, -n, eduardo-chibas, 2021/07/29
- Re: Irregularities when using -v, -z, -n, Leonid Isaev (ifax), 2021/07/29
- Irregularities when using -v, -z, -n, eduardo-chibas, 2021/07/29
- Irregularities when using -v, -z, -n, eduardo-chibas, 2021/07/29
- Re: Irregularities when using -v, -z, -n, Leonid Isaev (ifax), 2021/07/29