lmi
[Top][All Lists]
Advanced

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

Re: [lmi] dash print vs. printf


From: Greg Chicares
Subject: Re: [lmi] dash print vs. printf
Date: Sat, 20 Apr 2019 14:36:22 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1

On 2019-04-17 22:36, Vadim Zeitlin wrote:
> On Wed, 17 Apr 2019 22:10:05 +0000 Greg Chicares <address@hidden> wrote:
[...]
> GC> [...] Is the best
> GC> practice to use 'printf' as the only replacement for 'echo', and
> GC> never 'print'?
> 
>  In short, yes, I think this is exactly right. In fact, I really don't know
> where has the idea of using print come from.

It worked with zsh, and shellcheck didn't complain about it, so...given
that it never did anything unexpected in the past (in a small handful of
error-reporting statements that were never actually executed until now),
I assumed it was portable.

> GC> [...] But there's that distressing series of
> GC> locale diagnostics, which I often see when I run 'apt-get upgrade'
> GC> as well. Overriding only the ones that are missing lets the
> GC> command complete, at least:
> GC> 
> GC> $LANGUAGE="$LANG" LC_ALL="$LANG" /usr/bin/print --help           
> GC> perl: warning: Setting locale failed.
> GC> perl: warning: Please check that your locale settings:
> GC>         LANGUAGE = "en_US.UTF-8",
> GC>         LC_ALL = "en_US.UTF-8",
> GC>         LC_TIME = "en_DK.UTF-8",
> GC>         LC_COLLATE = "C.UTF-8",
> GC>         LANG = "en_US.UTF-8"
> GC>     are supported and installed on your system.
> GC> perl: warning: Falling back to the standard locale ("C").
> GC> Use: /usr/bin/print <--action=VAL> [--debug] [MIME-TYPE:[ENCODING:]]FILE 
> [...]
> GC> 
> GC> ...and, better, if I instead follow your advice here:
> GC> 
> GC>   https://lists.nongnu.org/archive/html/lmi/2018-07/msg00018.html
> GC> | Presumably, if you changed it to C.UTF-8, this warning would disappear.
> GC> 
> GC> ...then the unwelcome diagnostics disappear:
> GC> 
> GC> $LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 /usr/bin/print --help
> GC> Use: /usr/bin/print <--action=VAL> [--debug] [MIME-TYPE:[ENCODING:]]FILE 
> [...]
> GC> 
> GC> I'll try that sort of override next time I 'apt-get upgrade'.
> GC> Or...assuming that this is a perl-specific problem
> 
>  No, it isn't. Perl just calls setlocale() and check for its error, which
> is the right thing to do (rather than silently ignoring it).
> 
> GC> there a perl-specific solution, like
> GC>   export PERL_USE_DEFAULT_LOCALE=1
> GC> ?
> 
>  No, I'm not aware of anything like this. The only solutions I can think of
> are:
> 
> 1. Just use C.UTF-8 locale.
> 2. Ensure that your system supports en_US.UTF-8 and en_DK.UTF-8 locales.
> 
> I guess you are reluctant to just do (1) as otherwise you would have done
> it a long time ago,

I use en_US.UTF-8 because that's more or less the language I speak and I
imagine this will help avoid surprises with currency formats and spell
checking; and en_DK.UTF-8 because it's like en_US but with reasonable
date and time formats.

> but I'm not sure what prevents you from doing (2). Or
> do you mean that your system already does support these locales (i.e. they
> both appear in "locale -a" output), yet setting them from Perl still fails?

I just happened to come across this here:
  https://archlinuxhacks.wordpress.com/2012/07/19/locale-warnings-everywhere/
which says the standard advice is to run 'locale-gen' (which didn't
solve my problem in a chroot, for some reason that's probably documented
in some old message on this mailing list), and continues:
  "But when you double, even triple check everything and the same occurs
  again and again, it’s time to discard those solutions."
Then the author recommends running 'locale -a' (you say the same above),
and exporting whatever seems to be missing in shell startup files. Thus:

commit f9ed2d21
    Prevent locale issues
diff --git a/gwc/.zshrc b/gwc/.zshrc
-export LANG=en_US.UTF-8 LC_TIME=en_DK.UTF-8 LC_COLLATE=C.UTF-8
+export LANG=en_US.UTF-8 LC_ALL=C.UTF-8 LC_TIME=en_DK.UTF-8 LC_COLLATE=C.UTF-8

This morning I saw a different manifestation of the same problem:
  bsdtar: Failed to set default locale
in a terminal that I had opened before committing that change. Then I
pasted the relevant line into the terminal:
  export LANG=en_US.UTF-8 LC_ALL=C.UTF-8 LC_TIME=en_DK.UTF-8 LC_COLLATE=C.UTF-8
and reran the 'bsdtar' command, and it completed without any warning.



reply via email to

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