Gentoo Archives: gentoo-user

From: Eray Aslan <eray.aslan@×××××××.tr>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] 'if echo hello' in .bashrc
Date: Fri, 08 May 2009 14:57:15
Message-Id: 4A044845.7020306@caf.com.tr
In Reply to: Re: [gentoo-user] 'if echo hello' in .bashrc by Alan McKinnon
1 On 08.05.2009 17:10, Alan McKinnon wrote:
2 >>> if echo hello|grep --color=auto l >/dev/null 2>&1; then
3 >>> export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'
4 >>> fi
5 >>>
6 >>> to ~/.bashrc
7 >>>
8 >>> Why does he echo hello, please?
9 >> Some greps (like BSD one) might not support '--color' option, so "echo
10 >> hello|grep --color=auto l" will return error code, skipping if clause,
11 >> and won't break grep operation by adding an unsupported option.
12 >
13 > except that STDERR is combined with STDOUT and sent to /dev/null so the script
14 > will never get it, the if is always true and the entire check is redundant.
15 > Better would be
16 >
17 > if echo hello|grep --color=auto l >/dev/null ; then
18
19 No. We do not want any output from echo|grep. We just want the exit
20 code so that the following export statement gets executed iff grep
21 returns with no errors.
22
23 --
24 Eray