|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 ~ $ |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
In article <slrng0rr2i.7b0.stephane.chazelas@spam.is.invalid> ,
Stephane CHAZELAS <this.address@is.invalid> 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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 2008-04-22, Name withheld by request <anonb6e9@nyx3.nyx.net> 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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
In article <slrng0rv84.7t9.stephane.chazelas@spam.is.invalid> ,
Stephane CHAZELAS <this.address@is.invalid> 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. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|