LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   for loop in bash (https://www.linuxquestions.org/questions/programming-9/for-loop-in-bash-945544/)

ip_address 05-17-2012 10:23 AM

for loop in bash
 
Hello everyone,

As we can use this bash script

Code:

#!/bin/bash

for counter in {1..3};do

echo "$counter"

done



to generate this output:

Code:

1
2
3


How can I loop around in bash from 1 to 100 and A to Z all together.

so that output could be

Code:

1
2
3
4
.
.
.
.
100
A
B
C
.
.
.
Z

Thanks ..

millgates 05-17-2012 10:28 AM

Hi, how about

Code:

#!/bin/bash

for counter in {1..100} {A..Z};do

echo "$counter"

done

or, even better:

Code:

printf "%s\n" {1..100} {A..Z}

ip_address 05-17-2012 11:02 AM

@millgates .. thank you very much!!! That worked.

David the H. 05-18-2012 08:41 AM

See here for all you ever wanted to know about brace expansion:

http://wiki.bash-hackers.org/syntax/expansion/brace


And this link covers printf:

http://wiki.bash-hackers.org/commands/builtin/printf


All times are GMT -5. The time now is 08:49 AM.