It would NOT behave the same. The stderr is not sent thru the pipe
without that redirection. See below:
$ cat p
#!/usr/bin/perl
print STDERR "error!\n";
print STDOUT "output!\n";
No redirection:
$ ./p
error!
output!
Redirection as in the original post:
$ ./p 2>&1 >/dev/null | egrep -q output
$ echo $?
1
Notice the "failed" return code of 1? Because the pipe did not see the
string "output"...
Redirection grabbing stderr:
$ ./p 2>&1 >/dev/null | egrep -q error
$ echo $?
0
Notice the "success" return code of 0? Because the pipe did see the
string "error"...
$ ./p | egrep -q error
error!
$ echo $?
1
Notice the output ("error!") is your stderr - the egrep did not find it
because it did not see it. If it had, it would not print it because of
the "-q" option, and the return code would not show "failed" (1).
Please note (as I said in previous messages), that the redirection
(whether understood by the script's author or not) is doing what it was
intended to do: process the stderr and not the stdout in the pipeline.
Thanks,
Kevin
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of inode0
Sent: Monday, December 31, 2007 10:33 AM
To: Red Hat Enterprise Linux 5 (Tikanga) discussion mailing-list
Subject: Re: [rhelv5-list] Regular Expressions on RHEL 5
On Dec 31, 2007 11:41 AM, Collins, Kevin [MindWorks]
<[EMAIL PROTECTED]> wrote:
> Why are you so insistant that the '2>&1' is misplaced? It is perfectly
> well placed for its purpose, which is to allow the processing of
stderr
> but not stdout by the pipeline.
Because it generally serves no purpose where it is and would behave
exactly the same without it? Often this order of redirection indicates
a misunderstanding so I think people are just trying to get the OP to
think carefully about what the redirection is intended to accomplish.
John
_______________________________________________
rhelv5-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/rhelv5-list
_______________________________________________
rhelv5-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/rhelv5-list