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

Re: setlocale comma decimal question: GRACE and GMT



Glen Snyder wrote:
> Does anyone have an example of a bash script that would use setlocale to
> temporarily call on LC_NUMERIC to output comma decimals (and then switch
> back to the dot for the decimals afterwards)?

Question: Is it one single program that needs to both read *and* write
different formats at the same time?  Or is it two different programs.
Hopefully two different programs.  Set one locale for one program
reading data in one format and set another locale for the other
program writing the data so it will write in a different format.

The LC_NUMERIC environment variable can be set on the command line
like any variable can be.  In that syntax it only takes effect for the
current command.  Example assuming 

List a directory using your default locale.

  ls

List a directory using POSIX standard locale.

  LC_ALL=POSIX ls

List a directory using the en_US locale (assuming you have installed
it).  Note that in this case you get dictionary sort order with case
folded and punctuation ignored.  (Blech, but that is another story.)

  LC_ALL=en_US ls 

Therefore you could put something like this in your script.

  LC_NUMERIC=your_desired_locale yourprogram

All of the normal redirects and pipes work.  Therefore you could do
something like this.

  program1 | LC_NUMERIC=your_desired_locale program2 | program3

Sorry for the vagueness of this suggestion.  But you did not say
enough to grip the problem firmly.  But perhaps this will be enough.

Bob

Attachment: pgpbN3skI6fCw.pgp
Description: PGP signature


Reply to: