[plug] loop statement needed

Luke Dudney ldlist at westnet.com.au
Wed Mar 10 23:19:20 WST 2004


Jon Miller wrote:

>Does anyone know how to write a loop statement that can write out the alphabet.  It needs to increment starting with letter A and incrementing by 1 until it gets to the letter Z.
>
>
>Thanks
>
>  
>
In true UNIX admin style, I just took 20 minutes to figure out how to do 
this ten second task in just one second :)
Here's my bash version. I've probably just wasted 20 minutes as there 
must be an easier way to do it...

#!/bin/bash
 
function dec2oct {
 num=$1
 while [ $num -ne 0 ]; do
   rem=$(( $num % 8))
   num=$(( $num / 8 ))
   oc="${rem}${oc}"
 done
 echo $oc
}
 
i=65
while [ $i -le 90 ]; do
 octal=$(dec2oct $i)
 echo -e "\\$octal"
 let i="$i+1"
done

Cheers
Luke





More information about the plug mailing list