bug-autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: config.log claims invocation is FLAGS=foo bar when really FLAGS='foo


From: Kevin Brubeck Unhammer
Subject: Re: config.log claims invocation is FLAGS=foo bar when really FLAGS='foo bar'
Date: Mon, 07 Nov 2016 13:24:24 +0100

Eric Blake <address@hidden> čálii:

> On 11/04/2016 05:51 AM, Kevin Brubeck Unhammer wrote:

[...]

>> C=''
>> for i in "$@"; do
>>     i=$(echo "$i" | sed 's/\\/\\\\/g; s/\"/\\\"/g')
>>     C="$C \"$i\""
>> done
>> echo "$C"
>
> That works (although we'd want to tweak it to not pollute outside the
> autoconf namespace), but adds a number of forks to what is otherwise a
> fork-free output of "$@".  It's probably possible to optimize for the
> common case of arguments that don't need shell quoting to reduce some of
> the cost.  Since both lib/autoconf/general.m4 and lib/autoconf/status.m4
> output an invocation line, it's probably worth factoring out a common
> helper macro, probably to lib/m4sugar/m4sh.m4; would you like to try
> your hand at a patch? If not, I can probably do it.

I've tested the following to work under both dash and bash; and it only
runs sed if the argument contains a ‘'’.


#!/bin/sh
C=''
for i in "$@"; do
    case "$i" in
        *\'*)
           i=`printf "%s" "$i" | sed "s/'/'\"'\"'/g"`
           ;;
        *) :
           ;;
    esac
    C="$C '$i'"
done
printf " $0%s\n" "$C"


I tested by making a script containing

#!/bin/sh
C=''
for i in "$@"; do
    case "$i" in
        *\'*)
           echo 'fork!' >&2
           i=`printf "%s" "$i" | sed "s/'/'\"'\"'/g"`
           ;;
        *) :
           ;;
    esac
    C="$C '$i'"
done
printf "%s\n" "$@" >/tmp/gold
echo "Copy-paste this line, should give no output:"
printf " printf \"%%s\\\n\"  %s >/tmp/test; diff /tmp/gold /tmp/test\n" "$C"

and 

running e.g.

$ dash /tmp/esc.sh 'foo bar' 'x\"y' 'x\\"y'  'x\\\"y' 'x\\ \"y!' '!!' "foo'bar"

and copy-pasting the output. Seems to hold …


I don't know much about m4 though (and don't have much free time – but
then who does), so maybe it's best if you turn that into a real patch,
otherwise it's going to take quite a while :)



best regards,
Kevin Brubeck Unhammer

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]