LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-04-2008, 08:08 AM   #1
potraike
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Rep: Reputation: 0
Angry script executed inside another script dont make changes


Hello,

I have a script B that is executed inside a main script A. The script B make some changes in the environment variables like JAVA_HOME.
When I execute script B in command line everything's fine and the variables are updated.
When I execute script A, apparently the script B outputs the right things but the variables are not updated at the end. I've tried all the ways:

./scriptB.sh
. scriptB.sh
path/to/script/scriptB

please help me!!!!!
 
Old 03-04-2008, 09:12 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
If script B is called by script A, then you need to source script B for the variables in A to be effected.
 
Old 03-04-2008, 09:55 AM   #3
potraike
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Original Poster
Rep: Reputation: 0
ok the script B only works if it is entered like this in the command line:

. scriptB.sh

I almost reach the end of the internet with this problem...
I realy dont no why it as to be like that.
But i want to automize the process and that's why I want to execute script B inside script A....
 
Old 03-04-2008, 08:51 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
The point is that each time you start a new program, normally it starts a new sub-shell to run it in.
Shell env vars can only be exported (passed) downwards, not up, so when the sub-shell exits (completes), it's entire env, inc (sub-shell) vars disappears.
However, if you

source scriptB.sh

or

. scriptB.sh

(both do the same thing), then the scriptB.sh is run as if you had added the code directly into the caller prog (scriptA.sh), so created vars are retained in the scriptA.sh env.

Read this: http://www.tldp.org/LDP/abs/html/subshells.html

HTH
 
Old 03-05-2008, 06:27 AM   #5
potraike
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Original Poster
Rep: Reputation: 0
ok thanks that's great, thank you for your time.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Perl problem: script isn't executed but viewed jpostma Programming 10 02-08-2008 04:34 PM
Script is executed when user logout karthi26 Linux - Newbie 10 07-12-2007 08:26 AM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 10:10 PM
hotplug script executed 3 times Borelian Linux - Software 1 06-29-2004 12:46 AM
Simple script to be executed on startup. Korff Linux - General 2 06-03-2003 10:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:51 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration