bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error handling question


From: Marc Herbert
Subject: Re: Error handling question
Date: Tue, 10 Nov 2009 12:55:44 +0000
User-agent: Thunderbird 2.0.0.21 (X11/20090320)

Marc Herbert a écrit :
> Chris F.A. Johnson a écrit :
>>     For example, if you want to know whether user 'john' is in the
>>     password file:
>>
>> grep -q ^john: /etc/passwd
>>
>> You want to get the return code and execute code depending on the result
>>
>> (which can be 0, 1 or >1; 'if grep ...' is not adequate).
> 
> I find "if grep ..." adequate. Ignoring >1 here is just another small
> hole in the "set -e" safety net (and it will log an error message).


Just found this, even better: not even any extra hole in the "set -e"
safety net.


  set -e
  ...
  if grep -q ^john: /etc/passwd; then
      echo "FOUND"
  else grepstatus=$?
      # inspect $grepstatus for errors
  fi






reply via email to

[Prev in Thread] Current Thread [Next in Thread]