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

2006-08-28 Thread Com MN PG P E B Consultant 3
$ 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

Ronald
-- 
Ronald Fischer (phone +49-89-63676431)
mailto:[EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


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

2006-08-28 Thread Andreas Schwab
"Com MN PG P E B Consultant 3" <[EMAIL PROTECTED]>
writes:

> $ unalias fooee 2>&1 >/dev/null
> bash: unalias: fooee: not found
>
> Why is the error message displayed here?

Because you have redirected stderr (fd 2) to the channel connected to
stdout (fd 1) before stdout was redirected to a different channel (to
/dev/null).

> Because of the redirection, I had expected that any error message
> resulting from the unalias command would go to /dev/null

Read the bash manual, node Redirections:

   Note that the order of redirections is significant.  For example,
the command
 ls > DIRLIST 2>&1
   directs both standard output (file descriptor 1) and standard error
(file descriptor 2) to the file DIRLIST, while the command
 ls 2>&1 > DIRLIST
   directs only the standard output to file DIRLIST, because the
standard error was duplicated as standard output before the standard
output was redirected to DIRLIST.

Andreas.

-- 
Andreas Schwab, SuSE Labs, [EMAIL PROTECTED]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


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

2006-08-28 Thread Com MN PG P E B Consultant 3
> > $ unalias fooee 2>&1 >/dev/null
> > bash: unalias: fooee: not found
> >
> > Why is the error message displayed here?
> 
> Because you have redirected stderr (fd 2) to the channel connected to
> stdout (fd 1) before stdout was redirected to a different channel (to
> /dev/null).

Of course! Stupid me How could I make such a beginner's mistake!

Thank you for pointing this out.

Ronald Fischer
-- 
Ronald Fischer (phone +49-89-63676431)
mailto:[EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


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

2006-08-28 Thread Eric Blake
-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 [EMAIL PROTECTED]
-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-


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash