Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
dealing with spaces in "for i in `/bin/ls /some/dir`&qu
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
tvon
n00b
n00b


Joined: 10 Apr 2002
Posts: 46
Location: Baltimore MD, USA

PostPosted: Tue May 07, 2002 3:12 pm    Post subject: dealing with spaces in "for i in `/bin/ls /some/dir`&qu Reply with quote

Normally when I want to deal with the contents of a directory in a shell script, I will do something like

Code:

for i in `/bin/ls /home/tvon/Docs`
do
 echo ${i}
done


This normally works fine, but right now I am dealing with a Windows share and alot of the files/directories have spaces in them, so the result is something like this:

Code:

# ls /home/tvon/Docs
Pittsburgh
Popano Beach
Raleigh
Regina
Richmond
San Diego
San Francisco
# for i in `/bin/ls /home/tvon/Docs`
> do
>    echo ${i}
> done
Pittsburgh
Popano
Beach
Raleigh
Regina
Richmond
San
Diego
San
Francisco


Notice how the directories with spaces in thier names get split into two seperate iterations of the loop? This isnt good for me. I have tried some options to 'ls' but it seems that the "for i in.." loop always breaks on spaces.

Anyone know a way around this? Its a fairly simple thing and I'd hate to have to resort to Perl just because of this...

TIA,
-Tom

p.s. I'd love an email to tvon@gxs.ge.com in reply to this.
_________________

Python Powerd Web Hosting
http://www.etria.com/
Webware, Zope, CGI, More on request...
Back to top
View user's profile Send private message
Jeevz
Bodhisattva
Bodhisattva


Joined: 15 Apr 2002
Posts: 195
Location: Boston, MA

PostPosted: Tue May 07, 2002 6:13 pm    Post subject: Reply with quote

This works for me:

Code:

for i in /home/Administrator/* /c/*
do
echo ${i}
done


I'm not at home so I can't test this on my Gentoo box. However this works using Cygwin at work.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum