Bash script for files with spaces in the filenames

Mikkel L. Ellertson mikkel at infinity-ltd.com
Thu Feb 16 15:19:54 UTC 2006


Dotan Cohen wrote:
> Another friend has provided me with a simple bash script that performs
> an operation on all the files of a directory. However, many of the
> file names contain spaces. How can I modify the following code to work
> on files with spaces? The directory is on a mounted FAT32 partition.
> 
> 
> #!/bin/bash
> PWD=`pwd`
> for file in `find $PWD -name "*.mp3"`
> do
>   eyeD3 --force-update --set-encoding=utf8 "$file"
> done
> 
> 
> I had considered converting the spaces to underscores, but that would
> upset the delicate wife/linux balance in our household.
> 
> Thank you.
> 
> Dotan Cohen
> http://technology-sleuth.com/technical_answer/what_is_a_firewall.html
> 
I usually use something like:

#!/bin/bash
for file in *.mp3
do
  eyeD3 --force-update --set-encoding=utf8 "$file"
done

The only time you will run into a problem is if you have a directory
off the current directory that is named <something>.mp3.

Mikkel
-- 

  Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!




More information about the fedora-list mailing list