Answer the question
In order to leave comments, you need to log in
Why doesn't for loop work in bash?
Good afternoon! I need to write a script to check the length of an array in a loop, but something doesn't work (the actual script itself:
#!/bin/bash
#останавливаем службу
systemctl stop libvirt-guests
#объявляю массив и складываю в него результаты команды
unset array
array=(`virsh list | grep running | awk '{print $2}'`)
lenArr=${#array[@]}
#вот тут необходимо в бесконечном цикле проверять пока длина массива не будет равна 0
#и только тогда выполнить echo.
state=false
while [ state = true ]
do
if [ "$lenArr" -eq 0 ] ; then
echo "shutdown success"
state=true
break
else
continue
fi
done
Answer the question
In order to leave comments, you need to log in
state=false
while [ state != true ]
do
if [ "$lenArr" -eq 0 ] ; then
echo "shutdown success"
state=true
break
else
continue
fi
done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question