[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 10:27:08 +0200 |
I am getting confused with the following code
local aa
local bb=''
local cc='cc'
echo "local aa"
[[ -v aa ]] && echo "[[ -v aa ]]: Variable exists."
[[ ! -v aa ]] && echo "[[ ! -v aa ]]: Variable unknown."
[[ -z aa ]] && echo "[[ -z aa ]]: Variable exists, size is zero."
[[ ! -z aa ]] && echo "[[ ! -z aa ]]: Variable exists, size is positive
(not-zero)."
[[ -n aa ]] && echo "[[ -n aa ]]: Variable exists, size is positive
(not-zero)."
[[ ! -n aa ]] && echo "[[ ! -n aa ]]: Variable exists, size is zero."
# -------------------------------------------------------------
echo ""
echo "local bb=''"
[[ -v bb ]] && echo "[[ -v bb ]]: Variable exists."
[[ ! -v bb ]] && echo "[[ ! -v bb ]]: Variable unknown."
[[ -z bb ]] && echo "[[ -z bb ]]: Variable exists, size is zero."
[[ ! -z bb ]] && echo "[[ ! -z bb ]]: Variable exists, size is positive
(not-zero)."
[[ -n bb ]] && echo "[[ -n bb ]]: Variable exists, size is positive
(not-zero)."
[[ ! -n bb ]] && echo "[[ ! -n bb ]]: Variable exists, size is zero."
# -------------------------------------------------------------
echo ""
echo "local cc='cc'"
[[ -v cc ]] && echo "[[ -v cc ]]: Variable exists."
[[ ! -v cc ]] && echo "[[ ! -v cc ]]: Variable unknown."
[[ -z cc ]] && echo "[[ -z cc ]]: Variable exists, size is zero."
[[ ! -z cc ]] && echo "[[ ! -z cc ]]: Variable exists, size is positive
(not-zero)."
[[ -n cc ]] && echo "[[ -n cc ]]: Variable exists, size is positive
(not-zero)."
[[ ! -n cc ]] && echo "[[ ! -n cc ]]: Variable exists, size is zero."
# -------------------------------------------------------------
Here are the results:
local aa
[[ ! -v aa ]]: Variable unknown.
[[ ! -z aa ]]: Variable exists, size is positive (not-zero).
[[ -n aa ]]: Variable exists, size is positive (not-zero).
local bb=''
[[ -v bb ]]: Variable exists.
[[ ! -z bb ]]: Variable exists, size is positive (not-zero).
[[ -n bb ]]: Variable exists, size is positive (not-zero).
local cc='cc'
[[ -v cc ]]: Variable exists.
[[ ! -z cc ]]: Variable exists, size is positive (not-zero).
[[ -n cc ]]: Variable exists, size is positive (not-zero).
- Irregularities when using -v, -z, -n,
eduardo-chibas <=
- 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, 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