Answer the question
In order to leave comments, you need to log in
Why is the variable set inside the loop set to zero (bash script)?
Gentlemen, I'm writing a simple flow controller and I got into trouble, I feel that some kind of trifle, but I could not find it :(
The problem is that I process the loop and, if the condition is successful, I change the $freePipe variable to end the main loop, but I change it inside the second level loop and when I check it in the main loop to continue it or stop, then it is reset.Below is the simplified code
freePipe="0"
while [ "$freePipe" == 0 ]
echo $freePipe
do
echo "Начинаем подбор"
echo $freePipe
cat $ipListFile | while read line
do
freePipe=$line
echo "1 - $freePipe"
done
echo "2 - $freePipe"
sleep 1
echo "3 - $freePipe"
done
Answer the question
In order to leave comments, you need to log in
You call the outer cat command with the "|" pipeline, and everything that comes in a block after the pipeline will run in a separate shell. From here "echo 1 freePipe" will output the cat process internal variable, not your loop.
Yes, and to end the loop, use exit or break.
The break command can take an argument to end a loop of a particular nesting.
For example
while true
do
while true
do
while true
do
break 2
echo 3
done
echo 2
done
echo 1
done
while [ condition ]
do
op1
op2
done
A loaf and horns from a trolleybus.
gnu parallel or xargs will help you. https://debian.pro/1834
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question