Re: Bash script for files with spaces in the filenames

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/16/06, Dotan Cohen <dotancohen@xxxxxxxxx> 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.

The following script works fine with filenames containing spaces; just
compare it with yours:

#! /bin/sh
# mp32wav.sh

number=0

cd $1 || exit 1

for file in *.mp3
do
   wavfile=`echo $file | sed -e "s/[Mm][Pp]3$/wav/g"`
   echo $"Converting $file ..."
   lame --decode "$file" "$wavfile"
   echo $"Done"
   let "number += 1"
done

echo $"$number file(s) converted"

exit 0

Paul


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux