bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: Bug#343354: gettext-base: gettext.sh can't be sourced from zsh using


From: Bruno Haible
Subject: Re: Bug#343354: gettext-base: gettext.sh can't be sourced from zsh using the default zsh options (fwd)
Date: Mon, 19 Dec 2005 13:34:11 +0100
User-agent: KMail/1.5

Sergio Talens-Oliag <address@hidden> wrote:
> Using zsh with the option FUNCTION_ARGZERO set (the default), the
> gettext.sh script can't be sourced.
>
> I'm attaching a simple patch to fix it.
>
> [...]
>
> --- gettext.sh.in.orig        2005-05-20 22:14:33.000000000 +0200
> +++ gettext.sh.in     2005-12-14 17:19:13.386571720 +0100
> @@ -39,7 +39,20 @@
>  # $PREFIX/share/sh-scripts or $PREFIX/share/gettext. In order to not
> violate # the Filesystem Hierarchy Standard when doing so, this script is
> executable. # Therefore it needs to support the standard --help and
> --version. -case "$0" in
> +#
> +# To detect if the script has been called directly we define a test
> function. +# We do it this way to be able to source the script from zsh, as
> this shell +# replaces the $0 variable for sourced scripts and functions by
> default (this +# behaviour is controlled using the option
> FUNCTION_ARGZERO); by using a +# function we are sure that if
> FUNCTION_ARGZERO is set, $0 never takes the +# program name, while the
> program works as expected when $0 is not replaced. +# Note that using this
> method if we execute the script using zsh with the +# default options we
> will not see the --help or --version messages, but that +# is not
> important, as the executable script is run using '/bin/sh' and we get +#
> the desired efect when it is called directly.
> +
> +gettext_sh_fhs_test() {
> +  case "$0" in
>    gettext.sh | */gettext.sh | *\gettext.sh)
>      progname=$0
>      address@hidden@
> @@ -72,7 +85,11 @@
>      func_usage 1>&2
>      exit 1
>      ;;
> -esac
> +  esac
> +}
> +
> +# Test if we have been called as a script
> +gettext_sh_fhs_test $@
>
>  # eval_gettext MSGID
>  # looks up the translation of MSGID and substitutes shell variables in the

Thanks for the explanation of the problem. I find your solution of the
problem a bit risky: it would break the day zsh introduced two different
flags for controlling $0's behaviour in sourced script and functions, e.g.
SOURCED_ARGZERO and FUNCTION_ARGZERO. I'm therefore applying the
following patch instead.

*** gettext.sh.in       20 May 2005 21:06:00 -0000      1.2
--- gettext.sh.in       19 Dec 2005 12:37:05 -0000
***************
*** 39,44 ****
--- 39,50 ----
  # $PREFIX/share/sh-scripts or $PREFIX/share/gettext. In order to not violate
  # the Filesystem Hierarchy Standard when doing so, this script is executable.
  # Therefore it needs to support the standard --help and --version.
+ if test -z "$ZSH_VERSION"; then
+   # zsh is not POSIX compliant: By default, while ". gettext.sh" is executed,
+   # it sets $0 to "gettext.sh", defeating the purpose of this test. But
+   # fortunately we know that when running under zsh, this script is always
+   # being sourced, not executed, because hardly anyone is crazy enough to
+   # install zsh as /bin/sh.
    case "$0" in
      gettext.sh | */gettext.sh | *\gettext.sh)
        progname=$0
***************
*** 73,78 ****
--- 79,85 ----
        exit 1
        ;;
    esac
+ fi
  
  # eval_gettext MSGID
  # looks up the translation of MSGID and substitutes shell variables in the

Bruno






reply via email to

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