[prog] echoing something to STDERR

Conor Daly conor.daly at oceanfree.net
Wed Nov 12 23:21:03 EST 2003


On Wed, Nov 12, 2003 at 10:00:04PM +0100 or so it is rumoured hereabouts, 
Hamster thought:
> On Wed, 12 Nov 2003 18:19:36 +0000
> Conor Daly <conor.daly at oceanfree.net> wrote:
> 
> > alias echoerr='echo $* >&2'
> > 
> > doesn't quite work.  The idea is that the '$*' should represent the
> > arguments to'echoerr'
> 
> The problem here is that because you have enclosed the alias in '''''', the
> $* is not being interpreted.

No, you need the ' to prevent the $* being interpreted by the shell at alias
creation time.

[cdaly at Valkerie cdaly]$ alias eecho='echo $* >&2'
[cdaly at Valkerie cdaly]$ alias
alias eecho='echo $* >&2'

[cdaly at Valkerie cdaly]$ alias eecho=echo $* >&2
[cdaly at Valkerie cdaly]$ alias
alias eecho='echo'

[cdaly at Valkerie cdaly]$ alias eecho="echo $* >&2"
[cdaly at Valkerie cdaly]$ alias
alias eecho='echo  >&2'

So the single quote is the only one that keeps the $*.  Now, if I do this
on the commandline, it appears to work but if I stick it in a bash script:

#########################
#!/bin/bash

alias eecho='echo $* >&2'

alias

eecho "stderr"
echo "stdout"
#########################

I get:

[cdaly at Valkerie cdaly]$ ./cdtest
alias eecho='echo $* >&2'
./cdtest: line 7: eecho: command not found
stdout

So something's wrong...

Conor
-- 
Conor Daly <conor.daly at oceanfree.net>

Domestic Sysadmin :-)
---------------------
Faenor.cod.ie
 10:17pm  up 20 days, 15:25,  0 users,  load average: 0.00, 0.00, 0.00
Hobbiton.cod.ie
 10:15pm  up 20 days, 15:24,  1 user,  load average: 0.10, 0.03, 0.01


More information about the Programming mailing list