Re: Appreciate advice on %if %foo || %bar syntax

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

 



In regard to: Re: Appreciate advice on %if %foo || %bar syntax, Tony...:
Tim Mooney skrev, on 30-08-2007 23:11:
In regard to: Re: Appreciate advice on %if %foo || %bar syntax, Tony...:

%define is_rhel5 %(test -f /etc/redhat-release && cat /etc/redhat-release | egrep -q 'release 5' && echo 1 || echo 0)

Thanks from somebody else :)

Quite another thing is, that a more rational test would be something like:

"test -f /etc/redhat-release && grep 'release 5' /etc/redhat-release &&
echo 1 || echo 0"

Except you probably want the -q option to grep, otherwise your macro might
end up resulting in

    release 51

Might, only tried it at the CLI and it works as expected there.

I just tried it in a spec file on RHEL5, and the problem I expected is
present.  I added your define:

%define is_rhel5 %(test -f /etc/redhat-release && grep 'release 5' /etc/redhat-release && echo 1 || echo 0)

to the top of a random spec file, and then I added

	echo is_rhel5='%{is_rhel5}'

into the prep, and ran

	rpmbuild -bp foo.spec

I was rewarded with the output:

is_rhel5=Red Hat Enterprise Linux Client release 5 (Tikanga)
1

As I indicated, because -q wasn't used with grep, the is_rhel5 ended up
containing both the output from grep and the 1 from echo.

The '-q' is only for "silent", equivalent to " > /dev/null 2>&1". It won't affect output.

I agree with the first sentence (though I would have said q == quiet), but
I don't understand how you can arrive at the second sentence after the
first.  -q absolutely affects the output of grep and egrep.  That's it's
point.

Getting rid of the useless cat was a good move, but I don't see any reason
to prefer grep over egrep here.

People who use egrep should understand what it's good for. People who use egrep should understand and be able to use Posix regexps. Using egrep where grep will do is redundant.

You're right, using extended grep where grep will do is "exceeding what is
necessary", so it meets a definition of redundant.

I've found, however, that it's easier for most people to use egrep as a
superset of grep (if you don't use EREs, it behaves as grep does) than it
is for people to remember the circumstances under which they should use
basic grep vs. the circumstances under which they need to switch to egrep.

Tim
--
Tim Mooney                              mooney@xxxxxxxxxxxxxxxxxxxxxxxxx
Information Technology Services         (701) 231-1076 (Voice)
Room 242-J6, IACC Building              (701) 231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164

_______________________________________________
Rpm-list mailing list
Rpm-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/rpm-list

[Index of Archives]     [RPM Ecosystem]     [Linux Kernel]     [Red Hat Install]     [PAM]     [Red Hat Watch]     [Red Hat Development]     [Red Hat]     [Gimp]     [Yosemite News]     [IETF Discussion]

  Powered by Linux