[TriLUG] bash spaces in filenames

Michael Tharp gxti at partiallystapled.com
Thu May 4 16:07:56 EDT 2006


James Tuttle wrote:
> I'm need to grab a few hundred songs out of a few thousand to dump to my
> wife's IPod.  I have a list of the files she selected and I wrote a
> little bash script to grab them and sync them to her IPod, but it fails
> on spaces in filenames.  Probably on things like ' and & and - also.
> Any ideas?
>
>
> #/bin/env bash
>
> FILES="Barry White - Let's Get It On.mp3
> Barry White - Shaft Theme.mp3"
>
> for file in $FILES
>   do
>     if [ -e $file ]; then
>       FILE_LIST="$file $FILE_LIST"
>     else
>       echo "$file doesn't exist"
>     fi
>   done
>
> snip
>
> Thanks,
> Jim
>   
Might do the trick:

FILE_LIST="'$file' $FILE_LIST

Could also try \" instead of ' but single quotes deal with strange 
characters more tactfully.

-- 
Michael Tharp

http://www.ircd-charybdis.org/
http://www.atheme.org/




More information about the TriLUG mailing list