On Friday 08 May 2009 16:38:30 Christian wrote:
> Hi Alan,
>
> Am Freitag, 8. Mai 2009 schrieb Alan McKinnon:
> > > Some greps (like BSD one) might not support '--color' option, so "echo
> > > hello|grep --color=auto l" will return error code, skipping if clause,
> > > and won't break grep operation by adding an unsupported option.
>
> is this really right?
>
> The result of
>
> if echo hello|grep --Acolor=auto l >/dev/null 2>&1; then echo hallo; fi
>
> is nothing. 

Which is equal to ), which in shell terms is true

Yes, it's the opposite to other languages.
Yes, it really should be that way.
The return value of successful process is by convention 0, which therefore is 
evaluated as true. Non-zero is false

> So the if clause is false although I pieped STDERR to
> /dev/null.
>
> > except that STDERR is combined with STDOUT and sent to /dev/null so the
> > script will never get it, the if is always true and the entire check is
> > redundant. Better would be
> >
> > if echo hello|grep --color=auto l >/dev/null ; then
>
> grep writes to STDERR if an error is occured.
>
> The result of
>
>  if echo hello|grep --Acolor=auto l >/dev/null ; then echo hallo; fi
                        ^
What's this? I didn't type it. 

-- 
alan dot mckinnon at gmail dot com

Reply via email to