[prog] echoing something to STDERR
Almut Behrens
almut-behrens at gmx.net
Thu Nov 13 01:20:00 EST 2003
On Wed, Nov 12, 2003 at 10:21:03PM +0000, Conor Daly wrote:
>
> ... 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...
alias expansion is by default only enabled for interactive shells.
So, if you need it in a script, you have to enable it explicitly.
In bash this is:
shopt -s expand_aliases
With this added to your above script you get (assuming it's named
test.sh):
$ ./test.sh
alias eecho='echo $* >&2'
stderr
stdout
$ ./test.sh >/dev/null
stderr
which is what you'd expect...
Almut
More information about the Programming
mailing list