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]

Re: Shell portability question


Daniel Jacobowitz <drow@mvista.com> writes:

>>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.

I'd guess the only way to fix that portably is to replace every use of
  echo "$something" | foo
with 
  foo <<EOF
$something
EOF

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


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