1 |
On Friday 8 May 2009, 16:51, Alan McKinnon wrote: |
2 |
|
3 |
> > > except that STDERR is combined with STDOUT and sent to /dev/null |
4 |
> > > so the script will never get it, the if is always true and the |
5 |
> > > entire check is redundant. Better would be |
6 |
> > > |
7 |
> > > if echo hello|grep --color=auto l >/dev/null ; then |
8 |
> > |
9 |
> > That will output an uncaptured error message if --color is not |
10 |
> > supported. |
11 |
> |
12 |
> which is the desired effect. It causes the if to be false and the grep |
13 |
> options are not enabled (as they are not supported) |
14 |
|
15 |
It's not the fact that the error message is left free to show on screen |
16 |
that makes the exit status true or false. |
17 |
If the file is sourced from a non-interactive environment, you don't want |
18 |
anything printed (and probably, in this case, neither if it's an |
19 |
interactive session). Capturing stderr does not change the exit status |
20 |
of the pipeline. |