Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-19-2004, 04:37 PM
|
#1
|
Member
Registered: Mar 2004
Posts: 91
Rep:
|
No effect when 'export' command executed in a script?
Hello,
I wish to use a script from time to time to set and export some variables, but I don't understand, it doesn't work! I probably have missed something basic, but I really don't get it...
Example:
script '/usr/bin/japanese_env', containing the following:
LANG=ja_JP.eucJP
LC_MESSAGES=ja_JP.eucJP
LC_CTYPE=ja_JP.eucJP
XMODIFIERS=@im=kinput2
#
export LANG
export LC_MESSAGES
export LC_CTYPE
export XMODIFIERS
In a terminal (xterm for instance), I wish that when I launch 'japanese_env',
the script exports the 4 variables LANG, LC_MESSAGES, LC_CTYPE, XMODIFIERS...
Which seems logical to me, but it doesn't work...
%japanese_env
%echo $LC_MESSAGES
fr_FR
instead of 'ja_JP.eucJP' as I expected.
I don't understand why, and I cannot find the answer in shell manuals.
Can you help?
Cheers,
Sylvain.
|
|
|
04-19-2004, 04:53 PM
|
#2
|
Senior Member
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938
Rep:
|
Having % as part of the prompt makes it look to me like you're using something other than bash (csh perhaps?). export works only for bourne shell derivatives. Which shell are you using in the script?
|
|
|
04-19-2004, 06:49 PM
|
#3
|
Member
Registered: Mar 2004
Posts: 91
Original Poster
Rep:
|
zsh is the shell I'm using, same problem with bash...
Hi Komakino,
I'm using zsh, and I observed the same problem with bash.
Example (with bash or with zsh):
% ~/TRUC contains the line export BID=blabla
Then I do chmod +x TRUC and then ./TRUC , and then echo $BID shows nothing!
So 'export doesn't work in a script' ?
On the other hand, export *in a command line* works fine:
% export BID=something
% echo $BID
something
Why's that? Any ideas?
Cheers,
Sylvain.
|
|
|
04-19-2004, 07:27 PM
|
#4
|
Member
Registered: Oct 2002
Location: Stoughton, MA
Distribution: Gentoo x86_64 & PPC
Posts: 949
Rep:
|
Try initializing and exporting them in the same line like:
#!/bin/sh
export LC_MESSAGES=ja_JP.eucJP
export LC_CTYPE=ja_JP.eucJP
I did this, then chmod +x'd it, ./script, then %echo $LC_MESSAGES and it worked fine.
|
|
|
04-20-2004, 01:39 PM
|
#5
|
Member
Registered: Mar 2004
Posts: 91
Original Poster
Rep:
|
Solution
This doesn't work either.
On the other hand, someone gave me the solution I was looking for.
% . ./script
and the variables exported by 'script' will be available in the current shell.
% source ./script
has the same effect.
Cheers,
Sylvain.
|
|
|
04-20-2004, 06:33 PM
|
#6
|
Member
Registered: Oct 2002
Location: Stoughton, MA
Distribution: Gentoo x86_64 & PPC
Posts: 949
Rep:
|
I must have made a mistake last night when I tried it cause it doesn't work for me now. I probably exported it right in the shell and then when I tried it in a script it looked like it worked. Exported variables are only supposed to effect child processes (unless done as you mentioned above), so since the terminal is parent to the script, the variable doesn't get passed to it.
I am still kinda new at shell programming myself
Last edited by Scruff; 04-20-2004 at 06:41 PM.
|
|
|
04-20-2004, 08:15 PM
|
#7
|
Member
Registered: Mar 2004
Posts: 91
Original Poster
Rep:
|
Ok!
No problem. Thanks anyway for yesterday.
And we have the solution now!
See you.
Sylvain.
|
|
|
All times are GMT -5. The time now is 08:12 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|