LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 04-19-2004, 03:37 PM   #1
sylvain_gnu
Member
 
Registered: Mar 2004
Posts: 91

Rep: Reputation: Disabled
Question 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.
 
Old 04-19-2004, 03:53 PM   #2
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
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?
 
Old 04-19-2004, 05:49 PM   #3
sylvain_gnu
Member
 
Registered: Mar 2004
Posts: 91

Original Poster
Rep: Reputation: Disabled
Question 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.
 
Old 04-19-2004, 06:27 PM   #4
Scruff
Member
 
Registered: Oct 2002
Location: Stoughton, MA
Distribution: Gentoo x86_64 & PPC
Posts: 949

Rep: Reputation: 30
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.
 
Old 04-20-2004, 12:39 PM   #5
sylvain_gnu
Member
 
Registered: Mar 2004
Posts: 91

Original Poster
Rep: Reputation: Disabled
Lightbulb 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.
 
Old 04-20-2004, 05:33 PM   #6
Scruff
Member
 
Registered: Oct 2002
Location: Stoughton, MA
Distribution: Gentoo x86_64 & PPC
Posts: 949

Rep: Reputation: 30
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 05:41 PM.
 
Old 04-20-2004, 07:15 PM   #7
sylvain_gnu
Member
 
Registered: Mar 2004
Posts: 91

Original Poster
Rep: Reputation: Disabled
Wink Ok!

No problem. Thanks anyway for yesterday.
And we have the solution now!
See you.
Sylvain.
 
  


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
my database export shell script run from command line but not form crontab saifee Linux - General 11 01-29-2012 09:24 AM
removing only most previously executed command from history? jagroop mand Linux - Newbie 2 01-19-2005 05:39 AM
hotplug script executed 3 times Borelian Linux - Software 1 06-28-2004 11:46 PM
How do I undo last command executed? Elfking Linux - General 4 02-05-2004 01:18 AM
Simple script to be executed on startup. Korff Linux - General 2 06-03-2003 09:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:29 PM.

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