<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body ><div>You must modify the shell that will run the second script, because that is the shell that the second script will inherit its environment from.</div><div>It sounds like something like this will work:</div><div>$ first.sh</div><div>$ . env.sh</div><div>$ second.sh</div><div><br></div><div><br></div><div><div style="font-size:75%;color:#575757">Sent from my Verizon Wireless 4G LTE Smartphone</div></div><br><br><br>-------- Original message --------<br>From: "Mark G. Harvey" &lt;markgharvey@yahoo.com&gt; <br>Date: 06/24/2013  5:28 PM  (GMT-05:00) <br>To: CLUE's mailing list &lt;clue@cluedenver.org&gt; <br>Subject: Re: [clue] env variables <br> <br><br><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt"><div><span style="font-size: 13px;"><br></span></div><div style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="font-size: small;"><br></span></div><div style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="font-size: 13px;">so removing #!/bin/bash/ at the top of the script to stay within the same shell session doesn't make any detectable difference</span></div><div style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="font-size: 13px;"><br></span></div><div style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="font-size: 13px;"><span>I also added sourcing the file where the variables are set ( #&nbsp;</span><span>source&nbsp;</span><span>/etc/profile.d/00_jdk.sh
 &nbsp;)&nbsp;</span><span style="background-color: transparent;">&nbsp;</span></span></div><div style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="background-color: transparent; font-size: 13px;"><br></span></div><div style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="background-color: transparent; font-size: 13px;">the variables PATH and JAVA_HOME show up correct when the script is running ... but when finished, the variables are still not changed</span></div><div style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="background-color: transparent; font-size: 13px;"><br></span></div><div style="background-color: transparent;"><span style="font-size: 13px;"><div style="background-color: transparent;">[root@87148-mondev01 ~]# echo $PATH</div><div style="background-color:
 transparent;">/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin &nbsp;... should be appended with&nbsp;<span style="background-color: transparent;">/usr/java/jdk1.7.0_21/bin</span></div><div style="background-color: transparent;">[root@87148-mondev01 ~]# echo $JAVA_HOME</div><div style="color: rgb(0, 0, 0); font-style: normal; background-color: transparent;">... should have an entry&nbsp;<span style="background-color: transparent;">/usr/java/jdk1.7.0_21/bin ... but it is blank&nbsp;</span></div></span></div><div style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="font-size: 13px;"><br></span></div><div style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="font-size: 13px;"><br></span></div><div style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="font-size: small;"><br></span></div><div style="font-family: 'Courier
 New', courier, monaco, monospace, sans-serif; font-size: 10pt;"><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;">  <div style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10pt;"> <div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt;"> <div dir="ltr"> <hr size="1">  <font size="2" face="Arial"> <b><span style="font-weight:bold;">From:</span></b> "dennisjperkins@comcast.net" &lt;dennisjperkins@comcast.net&gt;<br> <b><span style="font-weight: bold;">To:</span></b> CLUE's mailing list &lt;clue@cluedenver.org&gt; <br> <b><span style="font-weight: bold;">Sent:</span></b> Monday, June 24, 2013 2:56 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [clue] env variables<br> </font> </div> <div class="y_msg_container"><br><div id="yiv0803515501"><style type="text/css">#yiv0803515501 p
 {margin:0;}</style><div><div style="font-family: Arial; font-size: 12pt; color: rgb(0, 0, 0);">The proper place for these might be in one of the Bash config files.<br><br><hr id="yiv0803515501zwchr"><b>From: </b>"Stephen Queen" &lt;svqueen@gmail.com&gt;<br><b>To: </b>"Mark G. Harvey" &lt;markgharvey@yahoo.com&gt;, "CLUE's mailing list" &lt;clue@cluedenver.org&gt;<br><b>Sent: </b>Monday, June 24, 2013 2:37:49 PM<br><b>Subject: </b>Re: [clue] env variables<br><br><div dir="ltr"><div><div><div><div><div><div>When you add <br>#!/bin/bash<br></div>to the top of your script, you are starting a new shell. When the script completes, it exits that shell. Instead "source" you environmental variables. Create a file my_env that contains your export commands<br>
# cat my_env<br>export JAVA_HOME=/usr/java/jdk1.7.0_21<br>export PATH=$PATH:/usr/java/jdk1.7.0_21/bin<br><br></div>Then source the file <br></div>. my_env<br></div><div>(space between . and my_env, does not need to be executable).<br>
</div>Now when you<br></div># echo $JAVA_HOME<br>usr/java/jdk1.7.0_21<br># <br><br></div>Steve<br><div><br><div><div><div><div>&nbsp;<br></div></div></div></div></div></div><div class="yiv0803515501gmail_extra"><br><br><div class="yiv0803515501gmail_quote">
On Mon, Jun 24, 2013 at 1:54 PM, Mark G. Harvey <span dir="ltr">&lt;<a rel="nofollow" ymailto="mailto:markgharvey@yahoo.com" target="_blank" href="mailto:markgharvey@yahoo.com">markgharvey@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="yiv0803515501gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div style="font-size: 10pt; font-family: 'Courier New', courier, monaco, monospace, sans-serif;"><div>CLUE experts,&nbsp;</div><div><br>This puzzle is likely simple for you folks, but it has me stumped. &nbsp;I've done considerable digging but have found mixed advice.&nbsp;<br>
<br>I've created a script to download from a local repo via wget an rpm to install JDK ... no problem there.&nbsp;<br><br>Here's the part I can't get right ... setting the variables so I can run scripts to install Tomcat ... Any attempt will bomb if it can't find /usr/java/jdk1.7.0_21/bin &nbsp;<br>
<br><br># set JAVA_HOME variable &nbsp; ... tried in vain<br>echo "setting JAVA_HOME variable variable for the session"&nbsp;<br>JAVA_HOME=/usr/java/jdk1.7.0_21<br># export JAVA_HOME variable&nbsp;&nbsp;... tried in vain<br>echo "exporting JAVA_HOME variable variable for the session"&nbsp;<br>
export JAVA_HOME=/usr/java/jdk1.7.0_21<br>echo
 "JAVA_HOME variable: $JAVA_HOME"<br><br># set PATH variable for the session &nbsp;&nbsp;... tried in vain<br>echo "setting PATH variable for the session"&nbsp;<br>PATH=$PATH:/usr/java/jdk1.7.0_21/bin<br># export PATH variable for the session<br>
echo "exporting PATH variable for the subsequent sessions &amp; processes"&nbsp;<br>export PATH=$PATH:/usr/java/jdk1.7.0_21/bin<br>echo "show PATH variable: $PATH"<br><br>sleep 3 &nbsp;# wait<br><br># create script to set JAVA_HOME &amp; PATH variables in /etc/profile.d/00_jdk.sh script for all accounts<br>
# use echo command with single quotes to write the literal statement to the script<br>touch /etc/profile.d/00_jdk.sh<br>echo '#!/bin/bash' &gt;&gt; /etc/profile.d/00_jdk.sh<br>echo '# set JAVA_HOME in /etc/profile.d/00_jdk.sh script for all accounts' &gt;&gt; /etc/profile.d/00_jdk.sh<br>
echo 'JAVA_HOME=/usr/java/jdk1.7.0_21' &gt;&gt; /etc/profile.d/00_jdk.sh<br>echo '# set PATH in /etc/profile.d/00_jdk.sh
 script for all accounts' &gt;&gt; /etc/profile.d/00_jdk.sh<br>echo 'PATH=$PATH:/usr/java/jdk1.7.0_21/bin' &gt;&gt; /etc/profile.d/00_jdk.sh &nbsp;<br><br>sleep 3 &nbsp;# wait<br><br>echo "review contents of /etc/profile.d/00_jdk.sh"<br>
cat /etc/profile.d/00_jdk.sh<br><br><br>... results of install ... added some blank lines for readability ...<br><br>[root@87148-mondev01 ~]# ./<a rel="nofollow" target="_blank" href="http://dev_install_jdk1.7-1.0.0.sh/">DEV_install_jdk1.7-1.0.0.sh</a>&nbsp;<br>
installation: &nbsp;Oracle/Sun jdk 1.7 64-bit<br>remount /tmp with execute privledge<br>changed to /tmp<br>Pulling package from Artifactory Repo Management Server<br>--2013-06-24 13:24:38-- &nbsp;<a rel="nofollow" href="">https://&lt;RepoHost&gt;/artifactory/simple/ext-release-local/oracle/jdk/7u21-linux/jdk-7u21-linux-x64.rpm</a><br>
Resolving&nbsp;&lt;RepoHost&gt;... 10.33.44.10<br>Connecting to&nbsp;&lt;RepoHost&gt;|10.33.44.10|:443...
 connected.<br><br>HTTP request sent, awaiting response... 200 OK<br><br>Length: 85388149 (81M) [application/x-rpm]<br>Saving to: “jdk-7u21-linux-x64.rpm”<br><br>100%[=======================================================================================================================================&gt;] 85,388,149 &nbsp;52.7M/s &nbsp; in 1.5s &nbsp; &nbsp;<br>
<br>2013-06-24 13:24:40 (52.7 MB/s) - “jdk-7u21-linux-x64.rpm” saved [85388149/85388149]<br><br>jdk downloaded<br>check /tmp/ contents for jdk<br>-rw-r--r--. 1 root root 85388149 Jun &nbsp;6 16:46 jdk-7u21-linux-x64.rpm<br>install jdk rpm<br>
Preparing... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;########################################### [100%]<br>package jdk-2000:1.7.0_21-fcs.x86_64 is already installed &nbsp; &nbsp; &nbsp;........ due to subsequent running of this script<br>install jdk complete<br>
<br>setting JAVA_HOME variable variable for the session<br>exporting
 JAVA_HOME variable variable for the session<br><br>... when tested in the script, the correct answer shows up ...&nbsp;<br><br>JAVA_HOME variable: /usr/java/jdk1.7.0_21 &nbsp;&nbsp;<br><br>setting PATH variable for the session<br>exporting PATH variable for the subsequent sessions &amp; processes<br>
<br>... when tested in the script, the correct answer shows up ...&nbsp;<br><br><br>show PATH variable: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.7.0_21/bin:/usr/java/jdk1.7.0_21/bin<br>
<br>review contents of /etc/profile.d/00_jdk.sh<br>#!/bin/bash<br># set JAVA_HOME in /etc/profile.d/00_jdk.sh script for all accounts<br>JAVA_HOME=/usr/java/jdk1.7.0_21<br># set PATH in /etc/profile.d/00_jdk.sh &nbsp;script for all accounts<br>
PATH=$PATH:/usr/java/jdk1.7.0_21/bin<br>remount /tmp removing execute privledge<br>finished<br><br><br>... after script runs, when tested from CLI, variables not not correct
 ...&nbsp;<br><br>[root@87148-mondev01 ~]# echo $JAVA_HOME<br><br>[root@87148-mondev01 ~]# echo $PATH<br>/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin<br><br><br><br>[root@87148-mondev01 ~]# exit<br>logout<br>
<br>[vwadmin@87148-mondev01 ~]$ su -<br>Password:&nbsp;<br><br><br>... now the variable additions show up ... they come from the&nbsp;/etc/profile.d/00_jdk.sh script created as part of the JDK download &amp; install ...&nbsp;<br><br>[root@87148-mondev01 ~]# echo $PATH<br>
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.7.0_21/bin:/root/bin<br><br>[root@87148-mondev01 ~]# echo $JAVA_HOME<br>/usr/java/jdk1.7.0_21<br><br><br><br>... How can I get the variables to be available for the current root session &amp; usable for subsequent installations? &nbsp;Trying to avoid the logout / login ...&nbsp;<br>
<br><br><br>Thanks for your help. &nbsp;<br></div></div></div><br>_______________________________________________<br>
clue mailing list: <a rel="nofollow" ymailto="mailto:clue@cluedenver.org" target="_blank" href="mailto:clue@cluedenver.org">clue@cluedenver.org</a><br>
For information, account preferences, or to unsubscribe see:<br>
<a rel="nofollow" target="_blank" href="http://cluedenver.org/mailman/listinfo/clue">http://cluedenver.org/mailman/listinfo/clue</a><br></blockquote></div><br></div>
<br>_______________________________________________<br>clue mailing list: clue@cluedenver.org<br>For information, account preferences, or to unsubscribe see:<br>http://cluedenver.org/mailman/listinfo/clue</div></div></div><br>_______________________________________________<br>clue mailing list: <a ymailto="mailto:clue@cluedenver.org" href="mailto:clue@cluedenver.org">clue@cluedenver.org</a><br>For information, account preferences, or to unsubscribe see:<br><a href="http://cluedenver.org/mailman/listinfo/clue" target="_blank">http://cluedenver.org/mailman/listinfo/clue</a><br><br></div> </div> </div> </blockquote></div>   </div></body>