Search code examples
autoconf

Why do conditionals in autoconf scripts prefix variables with "x"?


Why do conditional statements in autoconf scripts prefix their variables with "x"? For example, the macro provided by GNU to test for Boost has conditionals such as

if test "x$want_boost" = "xyes"; then

Why is this not defined as:

if test "$want_boost" = "yes"; then

Solution

  • In some early shells, testing for an empty string variable wasn't as easy as it is now, so the best alternative was to see if "x$variable" was equal to just "x". Also, since that's apparently using test, that's simpler than trying to properly quote/escape sequences like '$x != "y"' without losing sanity and/or portability.