No effect when 'export' command executed in a script?
Linux - SoftwareThis 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.
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.
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.
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.