Gentoo Archives: gentoo-user

From: Alan McKinnon <alan.mckinnon@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] 'if echo hello' in .bashrc
Date: Fri, 08 May 2009 14:45:11
Message-Id: 200905081643.03943.alan.mckinnon@gmail.com
In Reply to: Re: [gentoo-user] 'if echo hello' in .bashrc by Christian
1 On Friday 08 May 2009 16:38:30 Christian wrote:
2 > Hi Alan,
3 >
4 > Am Freitag, 8. Mai 2009 schrieb Alan McKinnon:
5 > > > Some greps (like BSD one) might not support '--color' option, so "echo
6 > > > hello|grep --color=auto l" will return error code, skipping if clause,
7 > > > and won't break grep operation by adding an unsupported option.
8 >
9 > is this really right?
10 >
11 > The result of
12 >
13 > if echo hello|grep --Acolor=auto l >/dev/null 2>&1; then echo hallo; fi
14 >
15 > is nothing.
16
17 Which is equal to ), which in shell terms is true
18
19 Yes, it's the opposite to other languages.
20 Yes, it really should be that way.
21 The return value of successful process is by convention 0, which therefore is
22 evaluated as true. Non-zero is false
23
24 > So the if clause is false although I pieped STDERR to
25 > /dev/null.
26 >
27 > > except that STDERR is combined with STDOUT and sent to /dev/null so the
28 > > script will never get it, the if is always true and the entire check is
29 > > redundant. Better would be
30 > >
31 > > if echo hello|grep --color=auto l >/dev/null ; then
32 >
33 > grep writes to STDERR if an error is occured.
34 >
35 > The result of
36 >
37 > if echo hello|grep --Acolor=auto l >/dev/null ; then echo hallo; fi
38 ^
39 What's this? I didn't type it.
40
41 --
42 alan dot mckinnon at gmail dot com