LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-26-2007, 07:23 PM   #1
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Rep: Reputation: 30
Angry howto set 'locale LC_ALL=$MYVAR' within a script??


hello.. as in the subject, I cannot set that.
I've tryied lot of combinations, like
Code:
LOC="es_CO"
#first:
echo `LC_ALL=$LOC` 
#other:
echo `export LC_ALL=$LOC` 
#other:
`export LC_ALL=$LOC`
#other:
export LC_ALL=$LOC  
#and so on...
no one works.
anybody knows how to set that within a script, and take effect inmediatly as when we type "export LC_ALL=some_THING" in the shell?

tanks in advance
 
Old 01-26-2007, 07:32 PM   #2
FnordPerfect
Member
 
Registered: Dec 2006
Location: Germany
Distribution: Kubuntu (Feisty Fawn), Debian (SID)
Posts: 127

Rep: Reputation: 15
Hmm.. well, the last one should have worked!

for your interest, this backticks (``) don't belong there. They mean, everything (shell commands) between them would be executed in a sub-shell with its own shell environment.
Use double-quotes ("") instead.
Also, echo `export LC_ALL=$LOC` doesn't make sense to me at all.
 
Old 01-26-2007, 07:39 PM   #3
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Original Poster
Rep: Reputation: 30
nopes, it netiher doesn't work..
really strange ..or I just don't know how to handle it..

if anybody can suggest something it'll be appreciated
 
Old 01-26-2007, 09:40 PM   #4
dunric
Member
 
Registered: Jul 2004
Distribution: Void Linux, former Slackware
Posts: 498

Rep: Reputation: 100Reputation: 100
If I understand your problem correctly, you may need to source your script with LOC="es_CO" and export LC_ALL=$LOC expressions to affect current shell.
Code:
minike@mycomp:~$ source myscript
See man bash for details.
 
Old 01-26-2007, 09:43 PM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Type the following commands in the shell and tell me the output:

Code:
echo $LOC
LOC='test'
echo $LOC
export LC_ALL=$LOC
echo $LC_ALL
This worked for me both in a script and interactively ... I didn't need to source or anything.

Last edited by H_TeXMeX_H; 01-26-2007 at 09:47 PM.
 
Old 01-26-2007, 10:20 PM   #6
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Original Poster
Rep: Reputation: 30
thanks 4 answering, pals

dunric:
yes, you're right but look: you have to perform in interactive-mode the source myFile ... exactly what I don't need.. that's a job I need to be performed by the script.. in fact, I already tryied out to 'source myfile' within' another script..with no results.
it's look like those settings must be done only in interactive mode.. or I don't know howto make'em work from a script.. as far I know only that those (source and export) are not idependents progs, but build-in functions of the shell.
btw: I alerady saw man bash as well.

H_TeXMeX_H:
here I post what you ask for:
Code:
jp@tyson:~$ echo $LOC

jp@tyson:~$ LOC='test'
jp@tyson:~$ echo $LOC
test
jp@tyson:~$ export LC_ALL=$LOC
jp@tyson:~$ echo $LC_ALL
test
but.. don't know for what you need this.

any idea?

tnx-a-lot
 
Old 01-26-2007, 10:55 PM   #7
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by minike
H_TeXMeX_H:
here I post what you ask for:
Code:
jp@tyson:~$ echo $LOC

jp@tyson:~$ LOC='test'
jp@tyson:~$ echo $LOC
test
jp@tyson:~$ export LC_ALL=$LOC
jp@tyson:~$ echo $LC_ALL
test
but.. don't know for what you need this.

any idea?
Well, from what I can see, the commands work just fine. You can put them in a script and they will work just the same.

How do you know the commands don't work ?

Or, in other words, what is the purpose of the script, what does it need to do ? What about it doesn't work ? (specifically)
 
Old 01-26-2007, 11:57 PM   #8
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Original Poster
Rep: Reputation: 30
yes, in theory it's simple:
imagine a script asking 4 the locale setting, wolud be something like this:
Code:
#!/bin/sh
echo "insert value:";read OPT
export LC_ALL=$OPT
but, the best way to illustrate what's going on, is printing it... look this "u" script code:
Code:
#!/bin/sh
LOC="es_ES"
export LC_ALL=$LOC
echo `locale`
..and now, its output:
Code:
$ u
LANG=es_AR LC_CTYPE="es_ES" LC_NUMERIC="es_ES" LC_TIME="es_ES" LC_COLLATE="es_ES" LC_MONETARY="es_ES" LC_MESSAGES="es_ES" LC_PAPER="es_ES" LC_NAME="es_ES" LC_ADDRESS="es_ES" LC_TELEPHONE="es_ES" LC_MEASUREMENT="es_ES" LC_IDENTIFICATION="es_ES" LC_ALL=es_ES
at this point we can say "it's working!" ..but.. once finished, look a the locale output (in interactive-mode):
Code:
$ locale
LANG=es_AR
LC_CTYPE="es_AR"
LC_NUMERIC="es_AR"
LC_TIME="es_AR"
LC_COLLATE=C
LC_MONETARY="es_AR"
LC_MESSAGES="es_AR"
LC_PAPER="es_AR"
LC_NAME="es_AR"
LC_ADDRESS="es_AR"
LC_TELEPHONE="es_AR"
LC_MEASUREMENT="es_AR"
LC_IDENTIFICATION="es_AR"
LC_ALL=
as you can see.. the enviroment variables setted within a script seems to affect just to a sub-shell (and dying with it), leaving intact the "general" or "more-up" EVs

Im reading "the Unix programming enviroment" right now.. (an archeological document, I know) it's says something related to the "dot operator" which makes the command in a script to be executed in the actual shell, and not in a subshell.. but in practice I cannot make it work.

as far the only I know is it's envolved a shell/sub-shell situation in all of this.. but cannot find a solution..
 
Old 01-27-2007, 12:26 AM   #9
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Original Poster
Rep: Reputation: 30
read this -from the advanced bash script book-
Quote:
A script can export variables only to child processes, that is, only to commands or processes which that particular script initiates. A script invoked from the command line cannot export variables back to the command line environment. Child processes cannot export variables back to the parent processes that spawned them.
guess it's time to look 4 a solution in another direction..
 
Old 01-27-2007, 04:43 AM   #10
dunric
Member
 
Registered: Jul 2004
Distribution: Void Linux, former Slackware
Posts: 498

Rep: Reputation: 100Reputation: 100
You saw the bash manual page but probably didn't read
. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current shell environment ...


Contents of the rtfm script file:
Code:
#!/bin/sh
echo "insert value:";read OPT
export LC_ALL=$OPT
Source it to be executed in current shell, enter required value:
Code:
minike@mycomp:~$ locale
LANG=es_AR
LC_CTYPE="es_AR"
LC_NUMERIC="es_AR"
LC_TIME="es_AR"
LC_COLLATE=C
LC_MONETARY="es_AR"
LC_MESSAGES="es_AR"
LC_PAPER="es_AR"
LC_NAME="es_AR"
LC_ADDRESS="es_AR"
LC_TELEPHONE="es_AR"
LC_MEASUREMENT="es_AR"
minike@mycomp:~$ source rtfm
es_ES
minike@mycomp:~$ locale
LANG=es_ES
LC_CTYPE="es_ES"
LC_NUMERIC="es_ES"
LC_TIME="es_ES"
LC_COLLATE=C
LC_MONETARY="es_ES"
LC_MESSAGES="es_ES"
LC_PAPER="es_ES"
LC_NAME="es_ES"
LC_ADDRESS="es_ES"
LC_TELEPHONE="es_ES"
LC_MEASUREMENT="es_ES"
You had to listen more carefully next time
 
Old 01-29-2007, 02:11 AM   #11
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Original Poster
Rep: Reputation: 30
sorry about the delay posting here, but you know: no news, good news..
and mine were xactly that: this issue was fixed and I hurry up to finish the proggy involving all of this.

dunric:
despite of your last post gave me the idea of what to do, it continued having the problem I was traying to avoid: I didn't wanted to use the "source" word.. but just the script name. that was all about.
guess at this point is fair to tell how I did it:

here's the script that cannot be sourced by itself.. this is the solution I found:
Code:
#!/bin/sh
# this script is called ABC

echo "insert value:";read OPT
#here I don't try to source anymore, but
# ..I create a target file containing the options
echo "export LC_ALL=$OPT" > temp.file
what do we have at this point?
.a script owning the app name
.a file containging the results
but, again.. need the "source" world! this app is simplifying nothing at all!
how to invoke a script to perform a souce that it cannot perform??
...simple (I love this part):
Code:
echo "alias ABC='/usr/bin/ABC ; source temp.file'" >> /etc/profile
isn't it beauty?
--don't suggest to just change the name of /usr/bin/ABC,
coz it'll be invoked during boot-time as well, and invocation won't be to an alias.. at last the user don't have why to know all of this details, just one command.


want to thanks to all of you pals, just to be here helping eachother and making things work!

best regards!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
locale: Cannot Set LC_ALL to default locale: No such file or directory. asym Linux - General 11 10-24-2018 05:54 PM
"locale not supported by Xlib, locale set to C" Irad Linux - Software 3 06-25-2006 03:59 PM
locale: Cannot set LC_ALL to default locale: Invalid argument GadgetWiz Mandriva 1 03-31-2006 11:38 PM
quick question (LC_ALL locale) spamhippy Slackware 6 11-29-2005 04:49 AM
LANG/ LC_ALL variables on Suse not set.. code segfaults nkshirsagar SUSE / openSUSE 0 01-04-2005 05:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 09:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration