On 08.05.2009 17:10, Alan McKinnon wrote:
>>>    if echo hello|grep --color=auto l >/dev/null 2>&1; then
>>>      export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'
>>>    fi
>>>
>>> to ~/.bashrc
>>>
>>> Why does he echo hello, please?
>> Some greps (like BSD one) might not support '--color' option, so "echo
>> hello|grep --color=auto l" will return error code, skipping if clause,
>> and won't break grep operation by adding an unsupported option.
> 
> except that STDERR is combined with STDOUT and sent to /dev/null so the 
> script 
> will never get it, the if is always true and the entire check is redundant. 
> Better would be
> 
> if echo hello|grep --color=auto l >/dev/null ; then

No.  We do not want any output from echo|grep.  We just want the exit
code so that the following export statement gets executed iff grep
returns with no errors.

-- 
Eray


Reply via email to