Unix Shell - The preferred way to get locale-independent output

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > April 2004 > The preferred way to get locale-independent output





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author The preferred way to get locale-independent output
Emil Karlén

2004-04-23, 6:34 am

Hello,

my problem is a shell-script which reads the output from other programs
(stat) and uses that information to decide what is to be done.

After installing a new Linux I choose the language Swedish and
after that experienced a bug in my script (for making backups).

My current solution is a
LC_CTYPE=en
at the beginning of the script, but found out that
LC_NAME=en
would also do it.

Now I wonder if this is the preferred soulution. I also wonder why
LC_CTYPE=C
won't do. Shoulden't there be a C-locale?
Can I rely on that there is a "en"-locale on every system so
that my program is portable?

/Emil

Bill Marcum

2004-04-23, 12:34 pm

On Fri, 23 Apr 2004 11:55:21 +0200, Emil Karlén
<emil.karlen@tele2.se> wrote:
> Hello,
>
> my problem is a shell-script which reads the output from other programs
> (stat) and uses that information to decide what is to be done.
>
> After installing a new Linux I choose the language Swedish and
> after that experienced a bug in my script (for making backups).
>
> My current solution is a
> LC_CTYPE=en
> at the beginning of the script, but found out that
> LC_NAME=en
> would also do it.
>
> Now I wonder if this is the preferred soulution. I also wonder why
> LC_CTYPE=C
> won't do. Shoulden't there be a C-locale?
> Can I rely on that there is a "en"-locale on every system so
> that my program is portable?
>

All systems should have a C or POSIX locale. It's unlikely that you
would find one without "en".
How does your script fail if you use LC_CTYPE=C? Perhaps you should set
LC_ALL or LANG.


--
Giraffe: a ruminant with a view.
Emil Karlén

2004-04-25, 3:34 pm

Bill Marcum wrote:

> On Fri, 23 Apr 2004 11:55:21 +0200, Emil Karlén
> <emil.karlen@tele2.se> wrote:
> All systems should have a C or POSIX locale. It's unlikely that you
> would find one without "en".
> How does your script fail if you use LC_CTYPE=C? Perhaps you should set
> LC_ALL or LANG.
>
>


Ok, I have to correct myself a bit, using LC_CTYPE=C makes my program to
still use swedish, and since I suppose swedish is a very uncommon languge
to have installed, I expected LC_CTYPE=C make it use english, and that was
what I ment when I ment (won't do), which I maybe could have expressed at
bit clearer (the same is true when using LC_CTYPE=POSIX).
To be more clear. These are my environment variables set on my system which
I think are of interest:

LC_PAPER=sv_SE
LC_ADDRESS=sv_SE
LC_MONETARY=sv_SE
LC_NUMERIC=sv_SE
LC_TELEPHONE=sv_SE
LC_MESSAGES=sv_SE
LC_COLLATE=sv_SE
LC_IDENTIFICATION=sv_SE
LC_MEASUREMENT=sv_SE
LC_CTYPE=sv_SE
LC_TIME=sv_SE
LC_NAME=sv_SE

LANG=sv_SE
LANGUAGE=sv_SE:sv

Now, what will change the program output of "stat" to english?

LC_CTYPE=en : change
LC_CTYPE=C : no change (still swedish)

LC_NAME=en : change
LC_NAME=C : no change

LC_ALL=en : no change
LC_ALL=C : no change

LANG=en : no change
LANG=C : no change

Still a bit confused,
Emil

Bill Marcum

2004-04-26, 12:33 am

On Sun, 25 Apr 2004 21:26:11 +0200, Emil Karlén
<emil.karlen@tele2.se> wrote:
> LANG=sv_SE
> LANGUAGE=sv_SE:sv
>
> Now, what will change the program output of "stat" to english?
>
> LC_CTYPE=en : change
> LC_CTYPE=C : no change (still swedish)
>
> LC_NAME=en : change
> LC_NAME=C : no change
>
> LC_ALL=en : no change
> LC_ALL=C : no change
>
> LANG=en : no change
> LANG=C : no change
>
> Still a bit confused,
> Emil
>

You may need to install an english locale. "locale -a" should
tell what is presently installed.


--
Giraffe: a ruminant with a view.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com