# Setting configuration until end of parent bash session

**URL:** <https://www.ruby-forum.com/t/setting-configuration-until-end-of-parent-bash-session/191663>\
**Category:** Ruby\
**Created:** [July 15, 2010, 11:37pm UTC](https://www.ruby-forum.com/t/setting-configuration-until-end-of-parent-bash-session/191663 "2010-07-15T23:37:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [July 15, 2010, 11:37pm UTC](https://www.ruby-forum.com/t/setting-configuration-until-end-of-parent-bash-session/191663/1 "2010-07-15T23:37:17Z")

</div>

Any advice on how a ruby script can set a config info that’s per  
parent process. In other words I want to be able to do something like:

$ foo  
no setting

Then…

$ foo 10

Which will store 10 somehow. And when I run foo again it can output  
10.

$ foo  
10

But if I close my terminal and/or open a new terminal then it will  
have it’s own setting.

% foo  
no setting

Thanks.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [July 16, 2010, 12:20am UTC](https://www.ruby-forum.com/t/setting-configuration-until-end-of-parent-bash-session/191663/2 "2010-07-16T00:20:01Z")

</div>

Intransition wrote:

> Any advice on how a ruby script can set a config info that’s per  
> parent process.

Using an environment variable?

> In other words I want to be able to do something like:  
> …  
> But if I close my terminal and/or open a new terminal then it will  
> have it’s own setting.

Have foo set an environment variable and then exec a new shell. The  
foo script later can print the variable if it exists. Here is  
something off the top of my head. Untested. It spawns a new shell  
though and that may be too disruptive for your needs.

Bob

#!/bin/sh  
if [-n “$myuniquefoovar”]; then  
echo “$myuniquefoovar” # or possibly printf  
exit 0  
fi  
if [$# -ne 0]; then  
myuniquefoovar="$\*"  
export myuniquefoovar  
exec $SHELL  
fi  
exit 0

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [July 16, 2010, 2:10am UTC](https://www.ruby-forum.com/t/setting-configuration-until-end-of-parent-bash-session/191663/3 "2010-07-16T02:10:39Z")

</div>

On Jul 15, 6:19 pm, Bob P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> exit 0  
> fi  
> if [$# -ne 0]; then  
> myuniquefoovar=“$\*”  
> export myuniquefoovar  
> exec $SHELL  
> fi  
> exit 0

Thanks, I feel like I’ve gotten a step closer, but still no cigar. I  
was able to get the child shell, which is cool --and I can accept that  
if need to be o get this to work. But I can’t get the environment  
variable transfer into the new shell.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [July 16, 2010, 2:55am UTC](https://www.ruby-forum.com/t/setting-configuration-until-end-of-parent-bash-session/191663/4 "2010-07-16T02:55:09Z")

</div>

On Thu, Jul 15, 2010 at 2:35 PM, Intransition [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Which will store 10 somehow. And when I run foo again it can output
> 
> Thanks.

$ env FOO=“something” sh  
$ echo “${FOO}”  
something  
$ exit  
$ echo “${FOO}”

$ env FOO=“string for ruby to print” ruby -e ‘puts ENV[“FOO”]’  
string for ruby to print  
$ echo “${FOO}”

$

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [July 16, 2010, 2:49am UTC](https://www.ruby-forum.com/t/setting-configuration-until-end-of-parent-bash-session/191663/5 "2010-07-16T02:49:17Z")

</div>

On Jul 15, 8:10 pm, Intransition [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > exit 0
> 
> Thanks, I feel like I’ve gotten a step closer, but still no cigar. I  
> was able to get the child shell, which is cool --and I can accept that  
> if need to be o get this to work. But I can’t get the environment  
> variable transfer into the new shell.

Just discovered that capitalized variables (environment variables) are  
not transferred. But lowercase variables (shell variables) are.

So this will work! Thanks Bob.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [July 16, 2010, 5:26am UTC](https://www.ruby-forum.com/t/setting-configuration-until-end-of-parent-bash-session/191663/6 "2010-07-16T05:26:10Z")

</div>

On Jul 15, 8:27 pm, Intransition [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Just discovered that capitalized variables (environment variables) are  
> not transferred. But lowercase variables (shell variables) are.

Looks like I am wrong about this. I ran an isolated test and they both  
come through --not sure why my capitalized form was getting clobbered.
