This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Shell portability question


>From toplevel configure.in:

cat <<\EOF_SED > conftestsed
s/ --no[[^ ]]* / /
s/ --c[[a-z-]]*[[= ]][[^ ]]* / /
s/ --sr[[a-z-]]*[[= ]][[^ ]]* / /
s/ --ho[[a-z-]]*[[= ]][[^ ]]* / /
s/ --bu[[a-z-]]*[[= ]][[^ ]]* / /
s/ --t[[a-z-]]*[[= ]][[^ ]]* / /
s/ -cache-file[[= ]][[^ ]]* / /
s/ -srcdir[[= ]][[^ ]]* / /
s/ -host[[= ]][[^ ]]* / /
s/ -build[[= ]][[^ ]]* / /
s/ -target[[= ]][[^ ]]* / /
s/ [[^' -][^ ]*] / /
s/^ *//;s/ *$//
s,\\,\\\\,g; s,\$,$$,g
EOF_SED
baseargs=`echo " ${ac_configure_args} " | sed -f conftestsed`

So we go to some trouble to double backslashes.  But we pass
${ac_configure_args} to echo... from the POSIX description of echo:

The following operands shall be supported:

string
    A string to be written to standard output. If the first operand is -n,
or if any of the operands contain a backslash ( '\' ) character, the results
are implementation-defined.

It so happens that "ash" will eat '\1' in the string passed to echo, if you
use the builtin version of echo rather than an external one in /bin.  So if
someone puts a complicated --program-transform-name in the command line,
it'll get eaten.

It gets worse, though.  Autoconf appears to use several similar constructs. 
Even in 2.57, consider:
  for ac_arg
  do
    case $ac_arg in
    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
    | -silent | --silent | --silen | --sile | --sil)
      continue ;;
    *" "*|*"    "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
      ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
    esac

If ac_arg="'a\1b'", then that case statement matches using bash and doesn't
using ash.  I'm not sure why.  But if you add a space to it, then ash eats
the \1.  I don't think it's possible to give configure any arguments
containing backslashes and expect things to work out right.

Am I missing something?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]