On 2/25/10 2:05 AM, Matthew Strax-Haber wrote:

>>> Below is a simple demonstration of the unexpected behavior:
>>>
>>> SHELL 1:
>>> mattsh$ alias c=clear
>>> mattsh$ c () { echo foo; }
>>> mattsh$ clear
>>> foo
>>
>> Here c is the first word.  So it is replaced by the alias.  (I didn't
>> know this behavior before.  This is actually really surprising
>> behavior to me since I didn't expect a function definition to be a
>> simple command.)

When `c' is parsed and delimited as a token, it is in a position to be the
first word of a simple command.  The shell does not look ahead or apply
any grammar rules before performing alias substitution, so `c' is a valid
candidate for replacement.  Since there is an alias defined for `c', the
text is replaced.

This is as Posix specifies and how Posix shells behave.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/


Reply via email to