1 |
On Friday 08 May 2009 16:59:19 Etaoin Shrdlu wrote: |
2 |
> On Friday 8 May 2009, 16:10, Alan McKinnon wrote: |
3 |
> > On Friday 08 May 2009 16:01:14 Mike Kazantsev wrote: |
4 |
> > > On Fri, 8 May 2009 14:38:58 +0100 |
5 |
> > > |
6 |
> > > Stroller <stroller@××××××××××××××××××.uk> wrote: |
7 |
> > > > To find the part to which I refer you'll need to scroll down about |
8 |
> > > > halfway through that page to "Colorize grep"; the author advises |
9 |
> > > > adding: |
10 |
> > > > |
11 |
> > > > if echo hello|grep --color=auto l >/dev/null 2>&1; then |
12 |
> > > > export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32' |
13 |
> > > > fi |
14 |
> > > > |
15 |
> > > > to ~/.bashrc |
16 |
> > > > |
17 |
> > > > Why does he echo hello, please? |
18 |
> > > |
19 |
> > > Some greps (like BSD one) might not support '--color' option, so |
20 |
> > > "echo hello|grep --color=auto l" will return error code, skipping if |
21 |
> > > clause, and won't break grep operation by adding an unsupported |
22 |
> > > option. |
23 |
> > |
24 |
> > except that STDERR is combined with STDOUT and sent to /dev/null so |
25 |
> > the script will never get it, the if is always true and the entire |
26 |
> > check is redundant. Better would be |
27 |
> > |
28 |
> > if echo hello|grep --color=auto l >/dev/null ; then |
29 |
> |
30 |
> That will output an uncaptured error message if --color is not supported. |
31 |
|
32 |
which is the desired effect. It causes the if to be false and the grep options |
33 |
are not enabled (as they are not supported) |
34 |
|
35 |
-- |
36 |
alan dot mckinnon at gmail dot com |