[plug] loop statement needed

Bernd Felsche bernie at innovative.iinet.net.au
Wed Mar 10 23:26:16 WST 2004


On Wednesday 10 March 2004 23:19, Luke Dudney wrote:
> 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.

for c in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ; do
  echo $c
done

> 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

Sorry; you assumed a particular character set.

-- 
/"\ Bernd Felsche - Innovative Reckoning, Perth, Western Australia
\ /  ASCII ribbon campaign | I'm a .signature virus!
 X   against HTML mail     | Copy me into your ~/.signature
/ \  and postings          | to help me spread!





More information about the plug mailing list