[PATCH build 2/2] Clean up all conditional statements.

Alan Coopersmith alan.coopersmith at oracle.com
Sat Sep 18 01:08:42 PDT 2010


On 09/15/10 07:56 AM, Trevor Woerner wrote:
> -    if [ x"$FONTPATH" = x ]; then
> +    if [ -z "$FONTPATH" ]; then

> -    if [ x"$NOQUIT" = x1 ]; then
> +    if [ -n "${NOQUIT}" ]; then

Though the build script isn't as critical as the configure.ac scripts, you
still want to be careful with those, since there are known portability
pitfalls as explained in

http://www.gnu.org/software/autoconf/manual/html_node/Limitations-of-Builtins.html#index-g_t_0040command_007btest_007d-1701

    Posix also says that ‘test ! "string"’, ‘test -n "string"’ and
    ‘test -z "string"’ work with any string, but many shells (such
    as Solaris, AIX 3.2, UNICOS 10.0.0.6, Digital Unix 4, etc.) get
    confused if string looks like an operator:

           $ test -n =
           test: argument expected
           $ test ! -n
           test: argument expected

    Similarly, Posix says that both ‘test "string1" = "string2"’
    and ‘test "string1" != "string2"’ work for any pairs of strings,
    but in practice this is not true for troublesome strings that
    look like operators or parentheses, or that begin with ‘-’.

    It is best to protect such strings with a leading ‘X’, e.g.,
    ‘test "Xstring" != X’ rather than ‘test -n "string"’ or
    ‘test ! "string"’.


-- 
	-Alan Coopersmith-        alan.coopersmith at oracle.com
	 Oracle Solaris Platform Engineering: X Window System


More information about the xorg-devel mailing list