[PLUG] Re: filenames with spaces, shell programming ...
Russell Senior
seniorr at aracnet.com
Fri May 20 18:42:24 UTC 2005
>>>>> "Wil" == Wil Cooley <wcooley at nakedape.cc> writes:
Wil> On Fri, 2005-05-20 at 09:41 -0700, Russell Senior wrote:
>> I have got a file containing file names with spaces and exclamation
>> marks, etc. I want to, e.g., cmp -v two versions of these files,
>> something like:
>>
>> $ cmp -v $DIR1/$foo $DIR2/$foo
>>
>> 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?
Wil> Double-quotes around shell variables?
Wil> cmp -v "$DIR1/$foo" "$DIR2/$foo"
Wil> I'm not sure about the exclamation points though; lemme know if
Wil> the quotes handle those too.
That's too late, I think. The for loop already has $foo as
space-split tokens. Wrapping them in quotes will just quote the
mis-split tokens. E.g.:
$ touch "a b c" "d e f"
$ ls -1 * > fnames
$ for i in $(cat fnames) ; do echo $i ; done
a
b
c
d
e
f
--
Russell Senior ``I have nine fingers; you have ten.''
seniorr at aracnet.com
More information about the PLUG
mailing list