[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
- Re: Error handling question, (continued)
- Re: Error handling question, Ciprian Dorin, Craciun, 2009/11/09
- Re: Error handling question, Greg Wooledge, 2009/11/09
- Re: Error handling question, Ciprian Dorin, Craciun, 2009/11/09
- Re: Error handling question, Greg Wooledge, 2009/11/09
- Re: Error handling question, Sven Mascheck, 2009/11/09
- Re: Error handling question, Chet Ramey, 2009/11/09
- Re: Error handling question, Sven Mascheck, 2009/11/09
- Re: Error handling question, Marc Herbert, 2009/11/09
- Re: Error handling question, Chris F.A. Johnson, 2009/11/09
- Re: Error handling question, Marc Herbert, 2009/11/10
- Re: Error handling question,
Marc Herbert <=
- Re: Error handling question, Chet Ramey, 2009/11/09
- Re: Error handling question, Marc Herbert, 2009/11/10
- Re: Error handling question, Chet Ramey, 2009/11/10