On Thu, Mar 3, 2011 at 01:14, Junio C Hamano <gitster@xxxxxxxxx> wrote: > Ãvar ArnfjÃrà Bjarmason Â<avarab@xxxxxxxxx> writes: > >> In a previous incarnation of the gettext series I implemented the >> eval_gettext() fallback like this: >> >>   eval_gettext() { >>     gettext_out=$(gettext "$1") >>     gettext_eval="printf '%s' \"$gettext_out\"" >>     printf "%s" "`eval \"$gettext_eval\"`" >>   } >> >> This was clever, but would incorrectly handle cases where the variable >> being interpolated contained spaces. E.g.: >> >>   cmd="git foo"; eval_gettext "command: \$cmd" >> >> Would emit "command: gitfoo", instead of the correct "command: git >> foo". > > Hmm, are you sure you got your quoting right? > >  Â$ cat >1.sh <<\EOF >  Â#!/bin/sh >  Âgettext () { >      Âcase "$1" in >      Â'command: $cmd') echo 'dcomman: $cmd' ;; >      Â*) echo "GETTEXT POISON" ;; >      Âesac >  Â} > >  Âeval_gettext() { >      Âgettext_out=$(gettext "$1") && >      Âgettext_eval="printf '%s' \"$gettext_out\"" && >      Âgettext_cmd=$(eval "$gettext_eval") && >      Âprintf "%s" "$gettext_cmd" >  Â} > >  Âcmd="git foo" >  Âeval_gettext "command: \$cmd" >  ÂEOF >  Â$ sh -x 1.sh >  Â+ cmd='git foo' >  Â+ eval_gettext 'command: $cmd' >  Â++ gettext 'command: $cmd' >  Â++ case "$1" in >  Â++ echo 'dcomman: $cmd' >  Â+ gettext_out='dcomman: $cmd' >  Â+ gettext_eval='printf '\''%s'\'' "dcomman: $cmd"' >  Â++ eval 'printf '\''%s'\'' "dcomman: $cmd"' >  Â+++ printf %s 'dcomman: git foo' >  Â+ gettext_cmd='dcomman: git foo' >  Â+ printf %s 'dcomman: git foo' >  Âdcomman: git foo > > Am I grossly missing something from what you are trying to do here? (CC-ing the list again, so there's a record of this in the mail archive). Your eval_gettext() is better, but it still fails in cases where the string contains "'s. E.g.: test_expect_success C_LOCALE_OUTPUT 'eval_gettext: our eval_gettext() fallback can interpolate variables with spaces in them' ' cmdline="git am" && export cmdline; printf "When you have resolved this problem run \"git am --resolved\"." >expect && eval_gettext "When you have resolved this problem run \"\$cmdline --resolved\"." >actual test_cmp expect actual ' If this were just: test_expect_success C_LOCALE_OUTPUT 'eval_gettext: our eval_gettext() fallback can interpolate variables with spaces in them' ' cmdline="git am" && export cmdline; printf "When you have resolved this problem run git am --resolved." >expect && eval_gettext "When you have resolved this problem run \$cmdline --resolved." >actual test_cmp expect actual ' Your version would work. Maybe there's some portable version of doing this that works with variables with spaces mixed with quotes. But unless someone can point it out I'll submit a series with git-sh-i18n--envsubst and tests demonstrating why it's needed soon.q -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html