Bash script for files with spaces in the filenames

Eric Brunson brunson at brunson.com
Fri Feb 17 22:32:56 UTC 2006


Here are a few comments on your buddy's script:

    * in bash PWD is maintained by the shell, so you don't need to set
      it with `pwd`
    * you don't need to call "find $PWD", anyway, you can just do "find
      .", since . *is* $PWD
    * back ticks in shell scripts are so 1989, the preferred method
      since 1994 is this:  $( some shell script )
    * "for file in $( something big )" could blow out the max size of
      the command line, which is usually around 4096 characters (I
      think, but I never encounter it, since I code around it)


Try this:

#!/bin/bash
find | while read file
do
 eyeD3 --force-update --set-encoding=utf8 "$file"
done



Justin Zygmont wrote:
> I'd use sed in the script.
>
>
> On Thu, 16 Feb 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
>>
>>
>




More information about the fedora-list mailing list