Setting configuration until end of parent bash session

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.

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

On Jul 15, 6:19 pm, Bob P. [email protected] 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.

On Thu, Jul 15, 2010 at 2:35 PM, Intransition [email protected]
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}”

$

On Jul 15, 8:10 pm, Intransition [email protected] 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.

On Jul 15, 8:27 pm, Intransition [email protected] 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.