<?xml version="1.0" encoding="windows-1252"?>
<node id="590038" title="Re: Env Variable value not persistent" created="2006-12-15 10:06:46" updated="2006-12-15 05:06:46">
<type id="11">
note</type>
<author id="178658">
hiseldl</author>
<data>
<field name="doctext">
&lt;p&gt;I don't know what you will be using it for, but if you just want to run a couple commands, then a sub-shell may work for you; just exit from the subshell, when you're done...&lt;/p&gt;

&lt;code&gt;# I use bash, but you can put csh here, if you want
# I added "--norc" so that PS1 is not overridden
$ perl -e '$ENV{SQUIRREL}="brown";$ENV{PS1}="subshell&gt; ";system("bash", "--norc")'
subshell&gt; echo $SQUIRREL
brown
subshell&gt; exit
exit
$ echo $SQUIRREL

$
&lt;/code&gt;

&lt;p&gt;The problem here is that you may forget that you're in a sub-shell and spawn several subshells.  One way to address that is to add an environment variable to your script, say, for example, &lt;code&gt;$ENV{MYSCRIPTISRUNNING}="YES"&lt;/code&gt;, then you could simply exit if this env variable exists, preventing multiple subshells.  This is not foolproof, but it's a start.&lt;/p&gt;
&lt;p&gt;N.B. This creates a &lt;strong&gt;sub&lt;/strong&gt;-shell, and the &lt;strong&gt;env changes will be lost&lt;/strong&gt; once you exit all the way out back to your original shell.&lt;/p&gt;


&lt;p&gt;HTH.&lt;/p&gt;


&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-178658"&gt;
&lt;P&gt;--&lt;br/&gt;[hiseldl]&lt;br/&gt;What time is it? It's [190308|Camel Time!]&lt;/P&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
590013</field>
<field name="parent_node">
590013</field>
</data>
</node>
