Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Big Dave

macrumors 6502
Original poster
Nov 27, 2007
314
25
Crestview, Fl
I would like to learn how to perform a while loop while inside a while loop. I have written a small bit of script that I would love to learn to simplify. Any help is appreciated.
-Thanks
Dave

Code:
#!/bin/bash
a="0"
b="0"
while [ $a -lt 10 ]
  do
    echo The a variable is $a and the b variable is $b.
    a=$[$a+1]
done
##########
a="0"
b="5"
while [ $a -lt 10 ]
  do
    echo The a variable is $a and the b variable is $b.
    a=$[$a+1]
done
 
Not really sure what your looking for

Code:
#!/bin/bash
a=0
while [ "$a" -lt 10 ]
  do

    b=0
    while [ "$b" -lt 10 ]
      do
          echo The a variable is $a and the b variable is $b.
          b=$[$b+1]
      done

    a=$[$a+1]
done
 
If you want to get fancy...

Code:
#!/bin/bash
a=0
while [ $a -lt 10 ]
  do

    b=0
    while [ $b -lt 10 ]
      do
          echo The a variable is $a and the b variable is $b.
          (( b+=1 ))
      done

    (( a+=1 ))
done
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.