Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
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
add comment

3 Answers

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
share|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
add comment

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

share|improve this answer
add comment

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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