POSIX alias expansion bugs (in bash 1.05)

Moderator, John S. Quarterman std-unix at longway.TIC.COM
Sat Mar 17 08:39:26 AEST 1990


From: Maarten Litmaath <uunet!cs.vu.nl!maart>

In article <1990Mar16.194728.21389 at usenet.ins.cwru.edu> of the newsgroup
gnu.bash.bug, chet at cwns1.CWRU.EDU (Chet Ramey) writes:
)...
)Sorry Maarten, it's not a bug.  It's how aliases are defined to behave.  The
)part I left out (because it's come up here before) is that aliases are 
)expanded when a command is *read*, not when it is executed.  Call that a
)design error, if you like, but bash and ksh do it the same way.

Conclusion: sometimes a `;' and a newline are NOT equivalent.  `Of course',
you might say, but I maintain it's a design bug, because of the unexpected
results.  Why can I say

	for i in *; do foo; done

instead of

	for i in *
	do foo
	done

but not

	alias foo=bar; foo

instead of

	alias foo=bar
	foo

?

)...  Alias expansion is done
)when the command line is tokenized (at least it should be, and I have
)redone expansion so it is -- vanilla bash does expansion on whole lines at
)a time).  So all aliases get expanded before any `alias' commands are
)executed.  [...]

I say: divide the line in logical commands and execute them in turn,
expanding aliases and functions at execution time.  That's far more natural
and I don't think it's much more difficult to program.

)>Bourne shell functions have the correct behavior.
)
)Bourne shell functions are not a complete replacement for bash/ksh aliases;
)they never will be.  It's possible, for instance, to write an alias
)`remote' such that 'remote x ls -l /bin/*' will pass its arguments to a
)remote machine x for evaluation; that's not possible with functions because
)globbing is done before the function is called.  [...]

Ridiculous!  If I say

	command /bin/*

then I don't want behavior dependent on the nature of `command'!
That's precisely the bug recently discussed in comp.unix.questions:

	$ x=external
	$ x=internal pwd >/dev/null
	$ echo "pwd is an $x command in this version of the shell"

You do NOT repeat NOT want to make the same mistake again!
(And POSIX neither.)

If I want argument evaluation on the remote machine, I will quote the
arguments, thank you!
--
 1) Will 4.5BSD have wait5()?         |Maarten Litmaath @ VU Amsterdam:
 2) Sleep(3) should be sleep(2) again.|maart at cs.vu.nl, uunet!mcsun!botter!maart

Volume-Number: Volume 19, Number 13



More information about the Comp.std.unix mailing list