colis-anr / morbig

A static parser for POSIX Shell
Other
190 stars 8 forks source link

interaction of alias expansion and parsing #53

Open treinen opened 5 years ago

treinen commented 5 years ago

there seems to be a problem with the way alias expansion is integrated in the engine. If alias expansion has an impact on the grammatical structure of the script then this is not recognized properly by morbig, at least not in the following example:

#!/bin/sh

alias si='if'
alias alors='then'
alias sinon='else'
alias cesttout='fi'
alias blabla='echo'

si [ -n a ]
alors
    blabla oui
sinon
    blabla non
cesttout

Morbig recognizes this as a sequence of simple commands insetad of an if-then-else.

yurug commented 5 years ago

bash has the same behavior as morbig. dash indeed recognizes an if-then-else.

Niols commented 5 years ago

Hum. I would say that dash is right. Maybe we should ask the POSIX mailing-list about that example?

yurug commented 5 years ago

The sentence explaining that point in the standard is:

After a token has been delimited, but before applying the grammatical rules in Shell Grammar, a resulting word that is identified to be the command name word of a simple command shall be examined to determine whether it is an unquoted, valid alias name.

How can you identify the command name word of a simple command without applying the grammar rules? It does not make sense to me.