1 |
Hi Alan, |
2 |
|
3 |
Am Freitag, 8. Mai 2009 schrieb Alan McKinnon: |
4 |
> > Some greps (like BSD one) might not support '--color' option, so "echo |
5 |
> > hello|grep --color=auto l" will return error code, skipping if clause, |
6 |
> > and won't break grep operation by adding an unsupported option. |
7 |
|
8 |
is this really right? |
9 |
|
10 |
The result of |
11 |
|
12 |
if echo hello|grep --Acolor=auto l >/dev/null 2>&1; then echo hallo; fi |
13 |
|
14 |
is nothing. So the if clause is false although I pieped STDERR to /dev/null. |
15 |
|
16 |
> except that STDERR is combined with STDOUT and sent to /dev/null so the |
17 |
> script will never get it, the if is always true and the entire check is |
18 |
> redundant. Better would be |
19 |
> |
20 |
> if echo hello|grep --color=auto l >/dev/null ; then |
21 |
|
22 |
grep writes to STDERR if an error is occured. |
23 |
|
24 |
The result of |
25 |
|
26 |
if echo hello|grep --Acolor=auto l >/dev/null ; then echo hallo; fi |
27 |
|
28 |
is: |
29 |
grep: Unbekannte Option »--Acolor=auto« |
30 |
Aufruf: grep [OPTION]... MUSTER [DATEI]... |
31 |
»grep --help« gibt Ihnen mehr Informationen. |
32 |
|
33 |
|
34 |
Best regard |
35 |
Christian |