One of my system have bash version 2.05.8, which is quite older. Now on this machine ii tried to use for loop in following format

 for i in {a..z}

But this gives , Please suggest the right statement

link|improve this question

61% accept rate
I'm not sure if you're using a and z as stand-ins for numbers, in which case the answer using seq should suffice, or if your intention is to generate the alphabet; could you please elaborate? – Eduardo Ivanec Apr 13 '11 at 14:26
Yes i want to generate a-z alphabets , not numbers – vnix27 Apr 13 '11 at 14:41
feedback

3 Answers

I'm not aware of a version of seq that works with letters. Do you have perl available? In that case:

for i in `perl -e "$,=' '; print a..z"`; do echo $i; done

I got the $,=' ' obscure part here: http://stackoverflow.com/questions/1445452/shell-script-for-loop-syntax

Of course I'm assuming you need to generate dynamic slices of the alphabet, otherwise this is probably not worth the effort and you should stick to:

for i 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 $i; done
link|improve this answer
Thanks for, for i in perl -e "$,=' '; print a..z"; do echo $i; done – vnix27 Apr 13 '11 at 15:53
feedback

Ranges only work for bash 3.0+

Your syntax is correct however:

#!/bin/bash
for i in {1..5}
do
    echo "$i) Bash version ${BASH_VERSION}"
done
link|improve this answer
1  
for i in {1..5}; do echp $i; done – 3molo Apr 13 '11 at 13:40
It doesn't works in my case due to older bash version – vnix27 Apr 13 '11 at 14:42
feedback

Try this instead: for i in $(seq 1 5)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.