 |
 |
Shell scripting, repeat with files, space in names (NEED HELP PLEASE)
|
 |
|
 |
|
Junior Member
Join Date: Sep 2000
Location: Milwaukee, WI
Status:
Offline
|
|
#!/bin/sh
files=`find -d '/Users/admin/Desktop/space space' -iname '*.webloc'`;
for i in $files; do
echo "$i";
done;
How do I allow the repeat loop to treat paths with spaces as one item?
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Sep 2000
Location: New York, NY
Status:
Offline
|
|
I'm not sure if Bourne shell has this feature, but Korn shell (now available as open source), and I presume pdksh use an environment variable called $IFS for Internal Field Separator. By default, it's set to space,tab,and newline. You could use ksh and reset this variable
Code:
#!/usr/bin/ksh
# remember IFS value so you can reset it
old_IFS=$IFS
# change IFS to just newline
IFS="\n"
for i in $files
do
echo $i
done
# reset IFS
IFS=$old_IFS
Rather than getting into ksh, you could do the same in Perl:
Code:
#!/usr/bin/perl
@files=`find ~/Desktop -iname "*.webloc"`;
foreach $file (@files) {
print "$file";
}
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status:
Offline
|
|
The cheapy quick answer is to temporarily move the folder to space_space, run the command, then move it back. There must be some sort of way to quote the names in the list?
As a second step you could use the -exec option of find to do your file manipulation from there. That way you wouldn't need the files variable.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Can't you just escape space characters with a "\"? Ie, /blah/blah/space\ space
?
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Sep 2000
Location: Milwaukee, WI
Status:
Offline
|
|
Suggestion to modify IFS was spot on. Thank you.
#!/bin/sh
files=`find -d '/Users/admin/Desktop/space space' -iname '*.webloc'`;
old_IFS=$IFS
IFS='
'
for i in $files
do
echo $i
done
IFS=$old_IFS
Interestingly enough IFS="\n" used n as a delimiter - makes sense..
Perl solution was known at the time, this is more an exercise in learning sh.
For anyone else who is curious, IFS by default is space tab return.
Thanks again, I really appreciate the help.
Nate
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|