Re: Check whether a macro is undefined or has a specific value

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

 



On 08/16/2011 12:26 PM, Marco wrote:
Thanks. I don't need to define another macro based on the value of
%{__foo}. However based on your suggestion, I think I can do this,
which seems to work:

%if %{?__foo:1}%{!?__foo:0}
%if "%{__foo}" == "1"
   echo "foo is defined and is 1"
%else
   echo "foo is defined, but has some other value: %{__foo}"
%endif
%else
   echo "foo is not defined"
%endif

Does this look correct/reliable enough or is there a better way to do
what I'm trying to do? Thanks.

I've never found documentation with the specifics of the %if macro, so testing to see what works is the best method I know. It seems like the above works. If you all need "do something" and "skip" block, the below is less verbose:

%if "%{?__foo:%{__foo}}%{!?__foo:0}" == "1"
  echo "foo is defined and is 1"
%else
  echo "foo is not defined or not equal to 1"
%endif

Alternatively, you could also define a macro that expands to the "do something" when needed, and expands to nothing otherwise. I don't know of simpler way to check equality though (but I'm kind of new to this stuff too).

Out of curiosity (if you don't mind me asking), why do you need to check both for definition and equality? What are you trying to do?

- Daniel

_______________________________________________
Rpm-list mailing list
Rpm-list@xxxxxxxxxxxxx
http://lists.rpm.org/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