[gnu.bash.bug] Alias bug in BASH 1.01

jkh@pcsbst.UUCP (jkh) (07/19/89)

The alias code is broken. Try the following:

bash% alias retch='echo \!*'
bash% retch foo bar blat
!* foo bar blat
bash%

The !* should expand into the current arg list, ala csh.
None of the other !<arg> constructs work in aliases either.

                                Jordan

P.S.:

function setenv () {
	eval $1=$2
	export $2
}

Works like a charm! Good job! I was all set to gripe about
not having setenv and being used to it and all, then I tried
that.. Ahem.. Never mind.

--------
                                Jordan Hubbard
                                PCS Computer Systeme GmbH
                                West Germany
        UUCP:                   {uunet,decwrl}!pyramid!pcsbst!jkh
        ARPA:                   jkh@violet.berkeley.edu

chet@kiwi.CWRU.EDU (Chet Ramey) (07/20/89)

In article <926@pcsbst.UUCP> jkh@meepmeep.pcs.com ( Jordan K. Hubbard ) writes:
>The alias code is broken. Try the following:
>
>bash% alias retch='echo \!*'
>bash% retch foo bar blat
>!* foo bar blat
>bash%
>
>The !* should expand into the current arg list, ala csh.
>None of the other !<arg> constructs work in aliases either.

It's not a bug, it's a design decision.

The alias mechanism in bash is more akin to the way ksh does it
(rather than csh) in that it only performs simple textual substitution.
If you want the ability to use arguments, use shell functions instead.

>function setenv () {
>	eval $1=$2
>	export $2
>}
>

This should be 
	eval $1="$2"
	export $1

or even
	export $1="$2"

You need to quote the second argument because it will be expanded (this
example is from Brian Fox, from a discussion we were having about this):

	foo="foo and bar"
	setenv baz "$foo"
	  setenv->$2 = foo and bar
	  eval $1=$2 -> baz=foo and bar
	NOT             baz="foo and bar"

Chet Ramey

Chet Ramey			"We are preparing to think about contemplating 
Network Services Group, CWRU	 preliminary work on plans to develop a
chet@cwjcc.INS.CWRU.Edu		 schedule for producing the 10th Edition of 
				 the Unix Programmers Manual." -- Andrew Hume