LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-17-2012, 10:23 AM   #1
ip_address
Member
 
Registered: Apr 2012
Distribution: RedHat
Posts: 42

Rep: Reputation: 2
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 ..
 
Old 05-17-2012, 10:28 AM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
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}
 
1 members found this post helpful.
Old 05-17-2012, 11:02 AM   #3
ip_address
Member
 
Registered: Apr 2012
Distribution: RedHat
Posts: 42

Original Poster
Rep: Reputation: 2
@millgates .. thank you very much!!! That worked.
 
Old 05-18-2012, 08:41 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
[SOLVED] Bash - While Loop reading from two lists simultaneously - nested while loop wolverene13 Programming 11 10-01-2011 05:00 PM
[SOLVED] [BASH] non-empty variable before loop end, is empty after exiting loop aitor Programming 2 08-26-2010 09:57 AM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 03:50 AM
Bash for loop Genjix Programming 5 12-23-2004 02:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration