1

the package I am trying to install has the following autogen.sh (only the first lines are showed):

#! /bin/sh
libtoolize --automake

However, on Mac, once GNU libtool has been installed (via MacPorts for instance), libtoolize is renamed as glibtoolize. Following this answer, I hence want to modify the autogen.sh above into:

#! /bin/sh
if [ $(hash libtoolize 2>&-) -eq 0 ]
then
        libtoolize --automake
else
        glibtoolize --automake
fi

But it returns ./autogen.sh: line 6: [: -eq: unary operator expected. What am I doing wrong here?

Community
  • 1
  • 1
tflutre
  • 3,354
  • 9
  • 39
  • 53

2 Answers2

3

I cannot comment (not enough rep yet), but I'd like to point out that these days, it might actually be best if you replaced the autogen.sh script by a simple call to the autoreconf tool, which was specifically created to replace all those autogen.sh, bootstrap.sh etc. scripts out there. It is part of any autoconf (not sure since when, but definitely was part of autoconf 2.63 (current is 2.68).

Max Horn
  • 552
  • 4
  • 16
1

The problem you have is $(hash libtoolize 2>&-) has no output, and so that line is interpreted as simply:if [ -eq 0 ]

The return code of the command is accessible via $?, so you could do:

hash libtoolize 2>&-
if [ $? -eq 0]; then
    #....

However, you could just as well do this:

if hash libtoolize 2>&-
then
        libtoolize --automake
else
        glibtoolize --automake
fi
Shawn Chin
  • 84,080
  • 19
  • 162
  • 191