qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] config-host.mak: escape configure arguments


From: Peter Maydell
Subject: Re: [Qemu-devel] [PATCH] config-host.mak: escape configure arguments
Date: Sun, 6 Oct 2013 00:54:08 +0900

On 5 October 2013 23:41, Gabriel Kerneis <address@hidden> wrote:
> Escape single quotes and newlines when writing configure arguments
> to config-host.mak. This is necessary to allow correct regeneration
> by re-executing configure in a shell when config-host.mak becomes
> out-of-date.
>
> Signed-off-by: Gabriel Kerneis <address@hidden>
> ---
>  configure | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/configure b/configure
> index 23dbaaf..fba7c1f 100755
> --- a/configure
> +++ b/configure
> @@ -3769,7 +3769,11 @@ echo "# Automatically generated by configure - do not 
> modify" >config-all-disas.
>
>  echo "# Automatically generated by configure - do not modify" > 
> $config_host_mak
>  printf "# Configured with:" >> $config_host_mak
> -printf " '%s'" "$0" "$@" >> $config_host_mak
> +for arg in "$0" "$@"; do
> +  # join each arg on a single line, escaping newlines and single quotes
> +  quoted_arg=$(echo "$arg" | sed ":a;N;s/\n/\\\\n/;ba" | sed "s/'/'\\\\''/g")

So this sed script appears to convert literal newlines in the input
into backslash-n:

mnementh$ foo='hello
> world'
mnementh$ quoted_arg=$(echo "$foo" | sed ":a;N;s/\n/\\\\n/;ba" | sed
"s/'/'\\\\''/g")
mnementh$ printf " '%s'" "$quoted_arg"
 'hello\nworld'

Is that what's intended? It doesn't seem very useful because if you cut-n-paste
(or pipe) 'hello\nworld' into a shell you get an actual backslash-n,
not a newline.

thanks
-- PMM



reply via email to

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