Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Jan 2002 21:27:45 +0100
From:      Cliff Sarginson <cliff@raggedclown.net>
To:        questions@FreeBSD.ORG
Subject:   Re: /dev/null 2>&1
Message-ID:  <20020115202745.GB7588@raggedclown.net>
In-Reply-To: <5.1.0.14.0.20020114115025.0372fe90@pop3s.schulte.org>
References:  <20020114174940.72104.qmail@web21210.mail.yahoo.com> <5.1.0.14.0.20020114115025.0372fe90@pop3s.schulte.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 14, 2002 at 11:53:39AM -0600, Christopher Schulte wrote:
> At 01:49 AM 1/15/2002 +0800, adrian kok wrote:
> >Hi Zaa
> >
> >Thank you. But what is the purpose for it on the
> >system?
> 
> Often when a command ( compile or cron job, for example ) wants to restrict 
> certain output.  In such cases the output might: confuse the user, add 
> jabber to the console, or generate unwanted email messages.
> 
> >>for example, if you type
> >
> >>find / -name foo > /dev/null 2>&1
> >
> >is seems that stdin is redirected to nowhere
> >(/dev/null)
> >and stderr is redirected to stdout e.g to /dev/null
> >too
> 
Yup.
Order is important. Doing the above the opposite way around has
a different effect.

find / -name foo 2>&1 >/dev/null

Will first redirect stderr to stdout, which at that moment
is directed to the terminal (well, or wherever it will be going
to if it is run under cron etc.). Then standard output is redirected
to /dev/null. Stderr however remains directed at what the standard
error *was* pointing at.

The commands are evaluated from left to right
-- 
Regards
Cliff



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020115202745.GB7588>