On 25/07/2020, TomK <firstname.lastname@example.org> wrote:
Out of curiosity and a bit on another topic. Is the syntax written
like this for compatibility reasons with other shells? Or because it
could get in the way of the parsers Automake uses?
Autoconf is primarily a portability tool and thus a key goal is for
generated configure scripts to run in pretty much any unix-like
environment that anyone could possibly want to run them on.
Although these days configure expects support for things like shell
functions and comments so you probably won't have much luck on the
original 1979 Bourne shell, but there are a lot of different ksh88
derivatives/workalikes still floating around which were the basis
for POSIX standardization and the default shell on basically every
unix-like environment you're likely to encounter outside of museums.
"x$host_alias" != x;
I know adding 'x' or another character prevents failures when a variable
is empty but that's been deprecated for sometime.
I don't know of any shell that gets this wrong with empty variables.
But metacharacters are a problem. For example, if we write:
test "$a" != "hello"
then at least some shells, (e.g., heirloom-sh), fail if a="!" or
a="(", etc, even though it is valid according to POSIX:
$ test "$a" != "hello"
test: argument expected
$ echo $?
Prefixing with a benign (usually "x") string neatly avoids this problem:
$ test x"$a" != x"hello"
$ echo $?
It's simple enough to do that usually this pattern is applied everywhere
even in cases where it is not strictly necessary -- I don't need to know
whether or not host_alias can legitimately be set to '!'.
 is deprecated in favor of []
`` is deprecated in favor of $()
[[ ]] is not POSIX compliant, and won't work at all in many modern
shells including dash.
$() is POSIX but unfortunately not widely portable in practice, e.g.,
again in heirloom-sh:
$ a=$(echo hello)
syntax error: `a=$' unexpected