classes with `case'. Use `expr' instead.
Suggested by Paul Eggert.
* doc/autoconf.texi (Limitations of Builtins): Explain expr, the
`x' trick, and negated character classes.
+2000-05-25 Akim Demaille <akim@epita.fr>
+
+ * acgeneral.m4 (_AC_INIT_PARSE_ARGS): Don't use negated character
+ classes with `case'. Use `expr' instead.
+ Suggested by Paul Eggert.
+ * doc/autoconf.texi (Limitations of Builtins): Explain expr, the
+ `x' trick, and negated character classes.
+
2000-05-24 Didier Verna <didier@lrde.epita.fr>
* acgeneral.m4 (AC_INIT): Call _AC_PACKAGE before _AC_INIT.
-disable-* | --disable-*)
ac_feature=`echo "$ac_option" |sed -e 's/-*disable-//'`
# Reject names that are not valid shell variable names.
- case $ac_feature in
- *[[^-a-zA-Z0-9_]]*) AC_MSG_ERROR([invalid feature: $ac_feature]);;
- esac
+ expr "x$ac_feature" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+ AC_MSG_ERROR([invalid feature name: $ac_feature])
ac_feature=`echo $ac_feature | sed 's/-/_/g'`
eval "enable_$ac_feature=no" ;;
-enable-* | --enable-*)
ac_feature=`echo "$ac_option" | sed -e 's/-*enable-//;s/=.*//'`
# Reject names that are not valid shell variable names.
- case $ac_feature in
- [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid feature: $ac_feature]);;
- esac
+ expr "x$ac_feature" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+ AC_MSG_ERROR([invalid feature name: $ac_feature])
ac_feature=`echo $ac_feature | sed 's/-/_/g'`
case "$ac_option" in
*=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
-with-* | --with-*)
ac_package=`echo "$ac_option"|sed -e 's/-*with-//;s/=.*//'`
# Reject names that are not valid shell variable names.
- case $ac_package in
- [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid package: $ac_package]);;
- esac
+ expr "x$ac_package" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+ AC_MSG_ERROR([invalid package name: $ac_package])
ac_package=`echo $ac_package| sed 's/-/_/g'`
case "$ac_option" in
*=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
-without-* | --without-*)
ac_package=`echo "$ac_option" |sed -e 's/-*without-//'`
# Reject names that are not valid shell variable names.
- case $ac_package in
- [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid package: $ac_package]);;
- esac
+ expr "x$ac_package" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+ AC_MSG_ERROR([invalid package name: $ac_package])
ac_package=`echo $ac_package | sed 's/-/_/g'`
eval "with_${ac_package}=no" ;;
*=*)
ac_envvar=`echo "$ac_option" | sed -e 's/=.*//'`
# Reject names that are not valid shell variable names.
- case $ac_envvar in
- [*[^a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid variable name: $ac_envvar]);;
- esac
+ expr "x$ac_envvar" : "[.*[^a-zA-Z0-9_]]" >/dev/null &&
+ AC_MSG_ERROR([invalid variable name: $ac_envvar])
ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
eval "$ac_envvar='$ac_optarg'"
export $ac_envvar ;;
*)
- case $ac_option in
- [*[^-a-zA-Z0-9.]*]) AC_MSG_WARN([invalid host type: $ac_option]);;
- esac
AC_MSG_WARN([you should use --build, --host, --target])
+ expr "x$ac_option" : "[.*[^a-zA-Z0-9.]]" >/dev/null &&
+ AC_MSG_WARN([invalid host type: $ac_option])
: ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
;;
No no, we are serious: some shells do have limitations :)
+You should always keep in mind that any built-in or command may support
+options, and therefore have a very different behavior with arguments
+starting with a dash. For instance, the innocent @samp{echo "$word"}
+can give unexpected results when @code{word} starts with a dash. It is
+often possible to avoid this problem using @samp{echo "x$word"}, taking
+the @samp{x} into account later in the pipe.
+
@table @asis
@item @command{case}
@cindex @command{case}
esac
@end example
+Alas, negated character classes are not portable (some old shells
+support the @samp{[!...]} syntax, some modern shells such as
+@command{zsh} support only the more recent syntax @samp{[^...]}). One
+solution can be:
+
+@example
+expr "$ac_feature" : ".*[^-a-zA-Z0-9_]" >/dev/null &&
+ @var{action}
+@end example
+
+@noindent
+or better yet
+
+@example
+expr "x$ac_feature" : ".*[^-a-zA-Z0-9_]" >/dev/null &&
+ @var{action}
+@end example
+
+It is somewhat more robust than the @samp{echo | grep} solution which
+suffers the limitations of @command{echo}: its argument should be too
+special (containing backslashes).
+
+
@item @command{unset}
@cindex @command{unset}
You cannot assume the support of @command{unset}, nevertheless, because
@command{egrep} also suffers the limitations of @command{grep}.
+@item @command{expr}
+@cindex @command{expr}
+Don't use @samp{\?}, @samp{\+} and @samp{\|} which are not supported by
+Solaris.
+
+There is no known command of @command{expr} starting with @samp{x}, so
+using @samp{expr x"@var{word}" : '@var{regex}'} avoids problems if
+@var{word} happens to have a meaning for @command{expr}.
+
@item @command{grep}
@cindex @command{grep}
Don't use @samp{grep -s} to suppress output, because @samp{grep -s} on
-disable-* | --disable-*)
ac_feature=`echo "$ac_option" |sed -e 's/-*disable-//'`
# Reject names that are not valid shell variable names.
- case $ac_feature in
- *[[^-a-zA-Z0-9_]]*) AC_MSG_ERROR([invalid feature: $ac_feature]);;
- esac
+ expr "x$ac_feature" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+ AC_MSG_ERROR([invalid feature name: $ac_feature])
ac_feature=`echo $ac_feature | sed 's/-/_/g'`
eval "enable_$ac_feature=no" ;;
-enable-* | --enable-*)
ac_feature=`echo "$ac_option" | sed -e 's/-*enable-//;s/=.*//'`
# Reject names that are not valid shell variable names.
- case $ac_feature in
- [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid feature: $ac_feature]);;
- esac
+ expr "x$ac_feature" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+ AC_MSG_ERROR([invalid feature name: $ac_feature])
ac_feature=`echo $ac_feature | sed 's/-/_/g'`
case "$ac_option" in
*=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
-with-* | --with-*)
ac_package=`echo "$ac_option"|sed -e 's/-*with-//;s/=.*//'`
# Reject names that are not valid shell variable names.
- case $ac_package in
- [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid package: $ac_package]);;
- esac
+ expr "x$ac_package" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+ AC_MSG_ERROR([invalid package name: $ac_package])
ac_package=`echo $ac_package| sed 's/-/_/g'`
case "$ac_option" in
*=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
-without-* | --without-*)
ac_package=`echo "$ac_option" |sed -e 's/-*without-//'`
# Reject names that are not valid shell variable names.
- case $ac_package in
- [*[^-a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid package: $ac_package]);;
- esac
+ expr "x$ac_package" : "[.*[^-a-zA-Z0-9_]]" >/dev/null &&
+ AC_MSG_ERROR([invalid package name: $ac_package])
ac_package=`echo $ac_package | sed 's/-/_/g'`
eval "with_${ac_package}=no" ;;
*=*)
ac_envvar=`echo "$ac_option" | sed -e 's/=.*//'`
# Reject names that are not valid shell variable names.
- case $ac_envvar in
- [*[^a-zA-Z0-9_]*]) AC_MSG_ERROR([invalid variable name: $ac_envvar]);;
- esac
+ expr "x$ac_envvar" : "[.*[^a-zA-Z0-9_]]" >/dev/null &&
+ AC_MSG_ERROR([invalid variable name: $ac_envvar])
ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
eval "$ac_envvar='$ac_optarg'"
export $ac_envvar ;;
*)
- case $ac_option in
- [*[^-a-zA-Z0-9.]*]) AC_MSG_WARN([invalid host type: $ac_option]);;
- esac
AC_MSG_WARN([you should use --build, --host, --target])
+ expr "x$ac_option" : "[.*[^a-zA-Z0-9.]]" >/dev/null &&
+ AC_MSG_WARN([invalid host type: $ac_option])
: ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
;;