Subject: sh expanding alias in odd place
To: None <tech-userlevel@netbsd.org>
From: Hubert Feyrer <hubert.feyrer@informatik.fh-regensburg.de>
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
gives:

	smaug% sh /tmp/x a
	default				<- should be "a"
	smaug% sh /tmp/x f
	f
	smaug% sh /tmp/x x
	default
	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




#!/bin/sh

alias a=ls

f() {
	date
}

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

-- 
Want to get a clue on IPv6 but don't know where to start? Try this:
* Basics -> http://www.onlamp.com/pub/a/onlamp/2001/05/24/ipv6_tutorial.html
* Setup  -> http://www.onlamp.com/pub/a/onlamp/2001/06/01/ipv6_tutorial.html 
Of course with your #1 IPv6 ready operating system -> http://www.NetBSD.org/