View previous topic :: View next topic |
Author |
Message |
tvon n00b
Joined: 10 Apr 2002 Posts: 46 Location: Baltimore MD, USA
|
Posted: Tue May 07, 2002 3:12 pm Post subject: dealing with spaces in "for i in `/bin/ls /some/dir`&qu |
|
|
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 |
|
|
Jeevz Bodhisattva
Joined: 15 Apr 2002 Posts: 195 Location: Boston, MA
|
Posted: Tue May 07, 2002 6:13 pm Post subject: |
|
|
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 |
|
|
|
|
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
|
|