printf "hi/000"|egrep hi #why no STDERR output

printf "hi/000"|egrep hi #why no STDERR output

am 22.04.2008 15:38:33 von anonb6e9

I do not understand why 'Binary file (standard input) matches' goes
to STDOUT, why not to STDERR?:

~ $ date;uname -sr
Tue Apr 22 08:35:42 CDT 2008
Linux 2.6.5-1.358
~ $ printf "hi\000"|egrep hi >foo
~ $ cat foo
Binary file (standard input) matches
~ $

Re: printf "hi/000"|egrep hi #why no STDERR output

am 22.04.2008 15:46:58 von Stephane CHAZELAS

2008-04-22, 13:38(+00), Name withheld by request:
> I do not understand why 'Binary file (standard input) matches' goes
> to STDOUT, why not to STDERR?:
>
> ~ $ date;uname -sr
> Tue Apr 22 08:35:42 CDT 2008
> Linux 2.6.5-1.358
> ~ $ printf "hi\000"|egrep hi >foo
> ~ $ cat foo
> Binary file (standard input) matches
> ~ $

Maybe because it's not an error.

--
St├ęphane

Re: printf "hi/000"|egrep hi #why no STDERR output

am 22.04.2008 16:44:37 von gazelle

In article ,
Stephane CHAZELAS wrote:
>2008-04-22, 13:38(+00), Name withheld by request:
>> I do not understand why 'Binary file (standard input) matches' goes
>> to STDOUT, why not to STDERR?:
>>
>> ~ $ date;uname -sr
>> Tue Apr 22 08:35:42 CDT 2008
>> Linux 2.6.5-1.358
>> ~ $ printf "hi\000"|egrep hi >foo
>> ~ $ cat foo
>> Binary file (standard input) matches
>> ~ $
>
>Maybe because it's not an error.

And maybe the sun rises in the east.

And yet you can see where he is coming from. In some sense, the term
"standard error" is a misnomer. It really is/should be "Out of Band".

Really, the standard error channel should be used for any OOB type
information - that is, other than the actual, genuine output of the command.

Re: printf "hi/000"|egrep hi #why no STDERR output

am 22.04.2008 16:58:12 von Stephane CHAZELAS

2008-04-22, 14:44(+00), Kenny McCormack:
[...]
>>> ~ $ printf "hi\000"|egrep hi >foo
>>> ~ $ cat foo
>>> Binary file (standard input) matches
>>> ~ $
>>
>>Maybe because it's not an error.
>
> And maybe the sun rises in the east.
>
> And yet you can see where he is coming from. In some sense, the term
> "standard error" is a misnomer. It really is/should be "Out of Band".
>
> Really, the standard error channel should be used for any OOB type
> information - that is, other than the actual, genuine output of the command.

In which way isn't the "Binary file (..." message "actual,
genuine output of grep"? It seems to me that it carries
information requested by the user (can "hi" be found in the
standard input?).

--
St├ęphane

Re: printf "hi/000"|egrep hi #why no STDERR output

am 22.04.2008 17:40:36 von Bill Marcum

On 2008-04-22, Name withheld by request wrote:
>
>
> I do not understand why 'Binary file (standard input) matches' goes
> to STDOUT, why not to STDERR?:
>
> ~ $ date;uname -sr
> Tue Apr 22 08:35:42 CDT 2008
> Linux 2.6.5-1.358
> ~ $ printf "hi\000"|egrep hi >foo
> ~ $ cat foo
> Binary file (standard input) matches
> ~ $
>
It's normal for (e)grep to produce output if it finds a match. If the
input were not considered binary, the matching line(s) would be output.
You can use the -a option to force *grep to treat its input as plain
text, or you can pipe the output of strings to *grep if you don't want
strange things to happen to your terminal.

Re: printf "hi/000"|egrep hi #why no STDERR output

am 22.04.2008 18:35:33 von gazelle

In article ,
Stephane CHAZELAS wrote:
>2008-04-22, 14:44(+00), Kenny McCormack:
>[...]
>>>> ~ $ printf "hi\000"|egrep hi >foo
>>>> ~ $ cat foo
>>>> Binary file (standard input) matches
>>>> ~ $
>>>
>>>Maybe because it's not an error.
>>
>> And maybe the sun rises in the east.
>>
>> And yet you can see where he is coming from. In some sense, the term
>> "standard error" is a misnomer. It really is/should be "Out of Band".
>>
>> Really, the standard error channel should be used for any OOB type
>> information - that is, other than the actual, genuine output of the command.
>
>In which way isn't the "Binary file (..." message "actual,
>genuine output of grep"?

The answer to that is obvious. You may not agree with it, but feigning
ignorance is not going to win you any points.

>It seems to me that it carries information requested by the user (can
>"hi" be found in the standard input?).

I see where you're going with this - but the point is that if you are
looking for a yes/no answer, you should be using the return status of
grep as your indicator, not trying to parse the output.

Re: printf "hi/000"|egrep hi #why no STDERR output

am 22.04.2008 23:00:27 von Ed Morton

On 4/22/2008 9:58 AM, Stephane CHAZELAS wrote:
> 2008-04-22, 14:44(+00), Kenny McCormack:
> [...]
>
>>>> ~ $ printf "hi\000"|egrep hi >foo
>>>> ~ $ cat foo
>>>> Binary file (standard input) matches
>>>> ~ $
>>>
>>>Maybe because it's not an error.
>>
>>And maybe the sun rises in the east.
>>
>>And yet you can see where he is coming from. In some sense, the term
>>"standard error" is a misnomer. It really is/should be "Out of Band".
>>
>>Really, the standard error channel should be used for any OOB type
>>information - that is, other than the actual, genuine output of the command.
>
>
> In which way isn't the "Binary file (..." message "actual,
> genuine output of grep"? It seems to me that it carries
> information requested by the user (can "hi" be found in the
> standard input?).
>

I think the information the user wanted was "the line where hi occurs in the
standard input". If they just wanted to know "can hi be found..." they'd have
used the -l or similair option to suppress printing the matching text.

Having said that, yes, I know this is how grep's designed and to get the output
from a binary file that you're used to getting otherwise would require "-a" (at
least with GNU grep) and I expect there's good reasons for it, but this:

$ printf "hi"| grep hi
hi
$ printf "hi"| grep -l hi
(standard input)
$ printf "hi\000"| grep hi
Binary file (standard input) matches
$ printf "hi\000"| grep -a hi
hi
$ printf "hi\000"| grep -a -l hi
(standard input)

isn't exactly intuitively obvious or consistent!

Ed.