[prog] echoing something to STDERR

Conor Daly conor.daly at oceanfree.net
Thu Nov 13 16:12:08 EST 2003


On Thu, Nov 13, 2003 at 12:20:00AM +0100 or so it is rumoured hereabouts, 
Almut Behrens thought:
> 
> 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 >/dev/null
> stderr
> 
> which is what you'd expect...

Yep, works.  However, on reading 

http://www.tldp.org/LDP/abs/html/aliases.html

it appears that the same alias may not work inside an if/then or a loop.
Defining a function within the script is much the better way to go...

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

Domestic Sysadmin :-)
---------------------
Faenor.cod.ie
  3:12pm  up 21 days,  8:20,  0 users,  load average: 1.02, 0.81, 0.40
Hobbiton.cod.ie
  3:10pm  up 21 days,  8:19,  2 users,  load average: 0.19, 0.06, 0.02


More information about the Programming mailing list