bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why doesn't this error message go to the bit bucket?


From: Eric Blake
Subject: Re: why doesn't this error message go to the bit bucket?
Date: Mon, 28 Aug 2006 05:57:13 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Thunderbird/1.5.0.5 Mnenhy/0.7.4.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Com MN PG P E B Consultant 3 on 8/28/2006 2:41 AM:
> $ unalias fooee 2>&1 >/dev/null
> bash: unalias: fooee: not found
> 
> Why is the error message displayed here? Because of the redirection,
> I had expected that any error message resulting from the unalias
> command would go to /dev/null

Your redirection operators are wrong - you asked bash to copy stderr to
the existing stdout, then silence stdout, but since the copy already took
place, you are not silencing stderr.  So error messages are going to the
original stdout, not /dev/null.  Try this instead:
$ unalias foo >/dev/null 2>&1

Also, if you want to be portable, remember that unalias is a builtin, but
that it is optional.  The only way to portably silence error messages when
your script is designed to run with other shells (such as ash) is to use a
subshell to test whether it will work first:

$ (unalias foo) >/dev/null 2>&1 && unalias foo

- --
Life is short - so eat dessert first!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFE8toZ84KuGfSFAYARAnCHAJ9ZuW980IB+xVTpn5/PEfk/EgUOIACcDR2c
zpYhYp0Pf9vmrta/wJynbj8=
=+76q
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]