LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-21-2010, 03:26 PM   #1
cryptinitedemon
LQ Newbie
 
Registered: Aug 2009
Posts: 4

Rep: Reputation: 0
Bash for loop not working


I have bash 4.0. I used the following for loop example, but all it outputs is "{1..10} instead of the actual numbers one through ten. why?

Code:
for a in {1..10}
do
  echo -n "$a "
done
 
Old 04-21-2010, 03:33 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Code:
[mherring@mystical play]$ for a in $(seq 1 10); do echo $a; done
1
2
3
4
5
6
7
8
9
10

[mherring@mystical play]$ for a in {1..10}; do echo $a; done
1
2
3
4
5
6
7
8
9
10
 
Old 04-24-2010, 08:45 AM   #3
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,045

Rep: Reputation: 65
Quote:
Originally Posted by cryptinitedemon View Post
I have bash 4.0. I used the following for loop example, but all it outputs is "{1..10} instead of the actual numbers one through ten. why?

Code:
for a in {1..10}
do
  echo -n "$a "
done
I don't see any problem with this.
 
Old 04-24-2010, 08:49 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I actually made a script and cut and pasted your code into it. Works fine.
 
Old 04-24-2010, 10:14 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by cryptinitedemon View Post
I have bash 4.0. I used the following for loop example, but all it outputs is "{1..10} instead of the actual numbers one through ten. why?

Code:
for a in {1..10}
do
  echo -n "$a "
done
I copy/pasted that right into my terminal and it printed out:

Code:
1 2 3 4 5 6 7 8 9 10
 
Old 04-24-2010, 10:44 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
First I'd check if braceexpand option is disabled for some reason:
Code:
set -o | grep braceexpand
it should be on by default.
 
  


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 On
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
Bash for loop rhlee Linux - Software 3 01-12-2010 03:59 AM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 03:50 AM
Bash loop using output of grep not working as needed Jim Pye Programming 7 01-16-2008 10:27 PM
Bash for loop Genjix Programming 5 12-23-2004 02:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:35 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