[mdlug] UNIX tips: Learn 10 good UNIX usage habits

Raymond McLaughlin driveray at ameritech.net
Wed Mar 12 01:13:57 EDT 2008


Robert Meier wrote:
> Ray, Aaron,
> 
>>  ~ $ echo "${VAR}a"
>>  tmp/*a
>>  ~ $ echo ${VAR}a
>>  tmp/a
>>
>> This all works the same for me, except that last one. On my system the
>> last two do the same thing:
>>
>>  pts/1 $ echo "{$VAR}a"
>>  {tmp/*}a
>>  pts/1 $ echo {$VAR}a
>>  {tmp/*}a
>>  pts/1 $
> 
>> I don't know if the author used a different shell, or has different
>> globbing options set, but I don't see just how that last one is even
>> supposed to work.
> 
> The difference is the subtle difference between {$ and ${ .
> The ${...} "quotes" the name inside which may have special variables, spaces,

As they say say in Springfield "Duoh!" It was right there, and I didn't
see it.


> {$ is treated as two separate tokens.
> The { is just a character prepended to the word, and $... evaluates
> the token that follows, which ends at the next space or special character.
> 
>   {$VAR}a is tokenized as '{'"$VAR"'}''a' .
>   ${VAR}a is tokenized as "${VAR}"'a'

Yes, thanks for clarifying.

>>> This article seems worth the read, but seems to need a little work.
> 
>> Yeah, it's not quite as clear as it should be....
> 
> I posted some suggestions to IBM.
> I included also the conflict between xargs (hint 8)
> which splits filenames with spaces and quoting (hint 4)
> which maintains filenames.

I'll keep an eye out for those. I haven't gotten that far yet, this
article is fairly challenging reading for me.

> I suggested using find ... | while read f; do ... "$f" ...; done
> as more portable, flexible, and less error prone.
> 
> Thanks for the pointer,





More information about the mdlug mailing list