From: Ævar Arnfjörð Bjarmason Date: Sat, 23 Oct 2010 11:32:47 GMT Subject: Re: Buglet in i18n? Message-ID: In-Reply-To: <20101022083450.GA8289@burratino> On Fri, Oct 22, 2010 at 08:34, Jonathan Nieder wrote: > Ævar Arnfjörð Bjarmason wrote: > >>         gettext () { >>             printf "%s" "$1" >>         } >> >>         eval_gettext () { >>             gettext_eval="printf '%s' \"$1\"" >>             printf "%s" "`eval \"$gettext_eval\"`" >>         } > > This looks wrong.  Consider a simplified example: > >        eval_gettext 'foo "bar baz"' > > Now eval_gettext is supposed to just interpolate $variable > substitutions, right?  In particular, the quotation marks > ought to be preserved. > > But instead, what gets evaluated is: > >        printf '%s' "foo "bar baz"" > > which splits as > >        printf '%s' 'foo bar' 'baz' > > which is equivalent to > >        printf '%s' 'foo bar' >        printf '%s' 'baz' > > with output > >        foo barbaz Indeed. It's a bug. > Maybe something like this would do it? > >        gettext_eval=$( >                printf '%s\n' "$1" | >                sed ' >                        s/[`\\"]/\\&/g >                        1 s/^/printf "%s" "/ >                        $ s/$/"/ >                ' >        ) && >        eval "$gettext_eval" That prints: foo "bar baz" (with double quotes) But what we want is: foo bar baz But what we're getting is: foo barbaz Have I got that right, sorry, not thinking clearly right now :)