[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: grep in spec file causes rpmbuild to abort with bad exit status
- From: bob proulx com (Bob Proulx)
- To: rpm-list redhat com
- Subject: Re: grep in spec file causes rpmbuild to abort with bad exit status
- Date: Wed, 10 Jan 2007 10:00:51 -0700
> marks wrote:
> > I'm using grep in the install section of my spec file to determine
> > if another file does or does not contain a piece of information.
> > rpmbuild is aborting with a "bad exit status" message when grep
> > does not find the item of interest.
>
> If you use it directly:
> if grep -q bla file; then
> ....
>
> rpmbuild doesn't exit.
Of the suggestions this way is my favorite and most clear method.
I know that you have the problem solved but I wanted to mention a
related problem that I have seen others ask. This is just drift from
the original question, but I think related.
The return code of grep indicates whether a pattern existed or not and
in the case here that is how it was being used. But another common
other case is that people are using grep to sift out a particular
pattern and the return code is not significant there. Well it is
actually significant (disk full problems, permission problems, etc.)
but people don't realize it. But the issue I am referring to here is
that the 'sh -e' setting will cause a non-zero return from grep to
exit the script.
grep PATTERN file1 > file2
grep -v PATTERN file1 > file2
This causes a non-zero return code based upon the PATTERN match.
> If you want to ignore the exit code of a command, then add ||: (ie. or true).
> Note that will change $? to true.
I have seen this several times in other people's scripts. I don't
like it because it loses I/O errors.
grep PATTERN file1 > file2 || true
grep -v PATTERN file1 > file2 || true
Better to use sed in this case.
sed -n /PATTERN/p file1 > file2
sed /PATTERN/d file1 > file2
The return code of sed is related only to errors occuring and not to
whether the pattern matched. The sed will fail when there is a real
error as desired and the script would terminate in that case.
Bob
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]