autoconf
[Top][All Lists]
Advanced

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

Re: config.status - robust sed substitutions


From: Robert Anderson
Subject: Re: config.status - robust sed substitutions
Date: 26 Feb 2003 14:19:46 -0800

On Wed, 2003-02-26 at 13:58, Andreas Schwab wrote:
> "Robert Anderson" <address@hidden> writes:
> 
> |> I submit for your critique an idea for making the generated sed
> |> commands within config.status be robust to "special" characters
> |> such as the delimiter  - which happens to have been chosen as ","
> |> - as well as sed metacharacters '&' and '\'.
> |> 
> |> This would be implemented as a small standalone script generated
> |> by config.status in /tmp, but the following gives the idea concisely:
> |> 
> |> #!/bin/ash
> |> 
> |> _quote_for_sed()
> |> {
> |>     echo "$1"| \
> 
> Look out for echo meta character.
> 
> |>    sed -e 's,\\,\\\\,g' | \
> |>    sed -e 's,&,\\&,g' | \
> |>    sed -e 's,\,,\\\,,g'
> |> }
> 
>         sed -e 's/[\&,]/\\&/g'
> 
> is much faster and works as well.

Yep.  Both problems ostensibly fixed below.  Can someone get this to
fail using their favorite crappy sh implementation?

#!/bin/ash

_quote_for_sed()
{
    cat<<_ACEOF | sed -e 's,[\&,],\\&,g'
$1
_ACEOF
}

_test()
{
    if [ "$substvar" = "$var" ]; then
        cat<<EOF
pass: $substvar == $var
EOF
    else
        cat<<EOF
FAIL: $substvar == $var
EOF
    fi
}

var='/tmp/file'
substvar=$( echo @var@ | sed -e "s,@var@,`_quote_for_sed $var`," )
_test

var='/tmp/,,file'
substvar=$( echo @var@ | sed -e "s,@var@,`_quote_for_sed $var`," )
_test

var='(&)[].*\~&<>/address@hidden|;:"'
substvar=$( echo @var@ | sed -e "s,@var@,`_quote_for_sed $var`," )
_test

var='\1abc\2\\20'
substvar=$( echo @var@ | sed -e "s,@var@,`_quote_for_sed $var`," )
_test

var="'"
substvar=$( echo @var@ | sed -e "s,@var@,`_quote_for_sed $var`," )
_test


Thanks,
Bob






reply via email to

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