Bash script for files with spaces in the filenames
Steven W. Orr
steveo at syslang.net
Thu Feb 16 14:49:13 UTC 2006
On Thursday, Feb 16th 2006 at 14:30 +0100, quoth Mathieu Chouquet-Stringer:
=>jvian10 at charter.net (Jeff Vian) writes:
=>> On Thu, 2006-02-16 at 11:29 +0200, Dotan Cohen wrote:
=>> > #!/bin/bash
=>> > PWD=`pwd`
=>> > for file in `find $PWD -name "*.mp3"`
=>> > do
=>> > eyeD3 --force-update --set-encoding=utf8 "$file"
=>> > done
=>> >
=>> In the above construct $file gets the first part up to the delimiter
=>> (white space) for each part it reads, so it may not have the full file
=>> name.
=>>
=>> I had a similar problem so I built something like this:
=>
=>Just replace the for loop by a while loop:
=>find $PWD -name "*.mp3" | while read file
=>
=>And you should be good to go...
Just be careful with this construct. It may do what you want but be aware
of what it won't do:
cnt=0
find | while read foo
do
echo "File name $cnt = $foo"
cnt=$(( cnt + 1 ))
done
echo $cnt
This will print out an incrementing counter in the loop but it will
print out a 0 for the final echo. That's because the instance of cnt in
the loop is in a seperate process from the instance out of the loop. They
are seperate variables. It's the pipe that creates the child.
--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
More information about the fedora-list
mailing list