[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible Bug in BASH

From: Chet Ramey
Subject: Re: Possible Bug in BASH
Date: Thu, 25 Feb 2010 10:41:17 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv: Gecko/20100111 Thunderbird/3.0.1

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.

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]