[PLUG] Re: filenames with spaces, shell programming ...

Paul Heinlein heinlein at madboa.com
Fri May 20 17:25:34 UTC 2005


On 5/20/05 9:58 AM, Wil Cooley wrote:

>> When I stupidly do something like:
>> 
>> $ for foo in $(cat fnames) ; do echo $foo ; cmp -v $DIR1/$foo
>> $DIR2/$foo ; done
>> 
>> the filenames get split at spaces in the filenames.  How do I keep 
>> them from being split?
> 
> Double-quotes around shell variables?
> 
> cmp -v "$DIR1/$foo" "$DIR2/$foo"
> 
> I'm not sure about the exclamation points though; lemme know if the 
> quotes handle those too.

The problem actually occurs earlier, in the for loop. The shell will 
assign $foo based on whitespace splits in the string returned by $(cat 
fnames). The quoting you suggest may help if $foo contains shell 
metacharacters, but it won't solve the whitespace issue.

-- 
Paul Heinlein <> heinlein at madboa.com <> www.madboa.com



More information about the PLUG mailing list