Subject: sh expanding alias in odd place
To: None <>
From: Hubert Feyrer <>
List: tech-userlevel
Date: 11/03/2001 00:13:48
[ Disclaimer: I haven't checked what the standards say on this one! ]

Andreas Lohrum (CC:'d) pointed me at this funky problem, which arises
occasionally when building pkgsrc/devel/pth (with some weird error in
shtool line 1280, and some appropriate .profile settings).

Running the script ("x") attached below with the following parameters

	smaug% sh /tmp/x a
	default				<- should be "a"
	smaug% sh /tmp/x f
	smaug% sh /tmp/x x
	smaug% sh /tmp/x ls
	a				<- uhu!

What happens here is that the "a" in "a )" in the case statement is
expanded to the value of the alias, and it matches only if the value of
the alias ("ls") is given, not "a". 

I think this is very non-intuitive, and wonder if this is correct
behaviour. This problem was tested on 1.5.3_ALPHA/sparc, from some code
digging it seems the problem is in readtoken() in src/bin/sh/parse.c
doing alias expansion in a place where it better shouldn't do so.

Does anyone want to comment? Shall I send-pr this? Thanks!

 - Hubert


alias a=ls

f() {

case $1 in
a )
	echo a
f )
	echo f
* )
	echo default

Want to get a clue on IPv6 but don't know where to start? Try this:
* Basics ->
* Setup  -> 
Of course with your #1 IPv6 ready operating system ->