[TriLUG] bash spaces in filenames

William Sutton william at trilug.org
Thu May 4 13:21:47 EDT 2006


If you're hard-coding the names (doubtful), just use \ escapes for those 
sorts of characters...otherwise, you might do the following (keep in mind 
that shell scripting isn't my strong suit so you may have to play around 
with the following pipe command):

$FILES=`find . -iname "*.mp3" |xargs sed -e"s/\ /\\\ /g" |sed 
-e"s/\&/\\\&/g" |<you get the idea>`

-- 
William Sutton

On Thu, 4 May 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
> 



More information about the TriLUG mailing list