I'm trying to make a basic loop, and I want to exit the nested loop when I loop the parent. The nested loop should restart each time the parent loops.
#!/bin/bash
loop1=0
i=0
while [[ $loop1 -eq "0" ]]; do
let "i+=1"
echo $i "--------------"
loop2=0
j=0
while [[ $loop2 -eq "0" ]]; do
let "j+=1"
echo $j $i
sleep .2
done &
loop2=1
sleep 2
done
My desired output would look like this:
1 --------------
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
2 --------------
1 2
2 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2
10 2
I'm getting that output, sort of, but the original nested loop doesn't terminate, so I also get 11 1, 12 1, 13 1, and so on.
I'm sure this is dead simple, but I'm not getting it.
$loop2 -eq 0when it looks like you want$j -lt 11?$loop2 -eq 0in hopes that changing the value of the variable would end the loop. But that didn't really pan out. Obviously this script is a simplification. My$jwon't necessarily be10$jisn't really relevant to what I'm trying to do. I'm just trying to get the basic mechanics working. I want to have nested loops, and I want to be able to kill the nested loop and start it over when the parent loops.