LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-11-2010, 02:04 PM   #1
rhlee
LQ Newbie
 
Registered: Aug 2009
Posts: 11

Rep: Reputation: 0
Bash for loop


Hi again LQ,

My question arises from trying out something I found in another LQ thread.

I use csplit to split up a large file and I get file xx01, xx02 and so on. I use a for loop to loop through the files.

Code:
for f in "xx**"
do
	echo test
	echo $f
done
Instead of getting

Code:
test xx01 test xx02 test xx03 ...
I get

Code:
test xx01 xx02 xx03 ...
Am I doing something wrong here?


Richard
 
Old 01-11-2010, 02:12 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
This works for me.

Code:
for f in $(ls xx**); do echo "test $f"; done
 
Old 01-11-2010, 02:17 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
It's all in the quotes:
Code:
[mherring@mystical tst]$ ls
xxa  xxb  xxc  xxd
[mherring@mystical tst]$ for fil in *;do echo "test";echo $fil;done
test
xxa
test
xxb
test
xxc
test
xxd
[mherring@mystical tst]$ for fil in "*";do echo "test";echo $fil;done
test
xxa xxb xxc xxd
[mherring@mystical tst]$
 
Old 01-12-2010, 03:59 AM   #4
rhlee
LQ Newbie
 
Registered: Aug 2009
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pixellany View Post
It's all in the quotes
Yes it is, thank you.

It works now.
 
  


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
[bash] if statements in a loop MarkGM Programming 3 04-02-2009 08:12 PM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 03:50 AM
BASH - while loop snorkytheweasel Linux - Desktop 2 03-26-2008 09:36 PM
Bash for loop Genjix Programming 5 12-23-2004 02:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:47 PM.

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