I am using following code to check whether variable is empty or not.
I'm using a while loop because I need to continue the loop while the variable is empty. The moment the variable is set to a value the loop should exit.
MR=[]
while [ -z "$MR" ]
do
echo "in while loop"
sleep 10s
MR="hi"
done
For some reason, it is not at all executing. What is the reason?
[]is not an empty array. It's a literal string[], which is not the empty string.MR=()(ignoring the fact thatMR=()doesn't actually define a variable; it only sets the array attribute on the nameMR).MR=()is basically equivalent todeclare -a MR.MRwill still test as undefined with[[ -v MR ]], for example, butdeclare -p MRwill show it asdeclare -a MR=().