autoconf
[Top][All Lists]
Advanced

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

Re: How do I make a portable test??


From: John Burger
Subject: Re: How do I make a portable test??
Date: Thu, 13 Feb 2003 23:41:15 -0500

From: "Dr. David Kirkby" <address@hidden>

[Much elided]

dnl something here generates an error:
dnl "test: ==: unexpected operator" on a Sun running NetBSD 1.6
if test $gsl_inc_count == 0 && test $gsl_lib_count == 0; then
   gsl_not_installed=1
elif test $gsl_inc_count != 2 || test $gsl_lib_count != 2; then
   gsl_incomplete=1
fi

I believe that the test operator = is more portable than ==. If you're really after numeric equivalence, there's a -eq operator that I think is fairly portable. For what it's worth, == is also unrecognized on Mac OS X, which has a BSD lineage as well.

A separate thing I noticed: if your variable gsl_inc_count is empty or undefined, test won't see it - its first argument will be your (intended) operator. For this reason, I always quote such variable arguments to test, if there's any chance they can be empty, e.g.,

  if test "$gsl_inc_count" = 0 && ...

Historically, the really retentive thing to do is something like:

  if test x"$gsl_inc_count" = x0 && ...

or, I suppose, for a numeric comparison this would work:

  if test 0"$gsl_inc_count" -eq 0 && ...

Usually, though, I can't bear to write such grotesqueries.

- John Burger
  The MITRE Corporation






reply via email to

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