• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Set Shell Environment Variable from Script

I have a Linux application which needs some environment variables set before it will run. These environment variables (e.g. SOME_VAR) are set by sourcing a script:
. set_envvars.sh

After doing that, I can run my application:
./My_App

I want to create a script which does both of these things. It is called init_my_app.sh and looks like:

Code:
#!/bin/sh

# source set_envvars.sh if it was not already
if [ -z "$SOME_VAR" ]; then
	echo "Sourcing set_envvars.sh"
	. ../.././set_envvars.sh
fi
./My_App

The problem with this is that when I source set_envvars.sh from a script, it does not set the parent's shell environment variables. So after executing this init script, if I type:

echo $SOME_VAR

It is not set.

I have read numerous things on the internet about this, and it seems people say if you source, rather than execute, it will set the parent's shell's variables. But I am sourcing it already.

How can I have the init script, which calls the set script, set the variable's for the parent shell?

I am using Ubuntu 12.04.4 LTS.

Thanks.
 
I've seen HPC clusters provide settings for a wide range of applications (scientific/proprietary/conficting versions) with Environment Modules.
http://modules.sourceforge.net/

One can definitely use a script:
Code:
#!/bin/sh
module load My_App
./My_App
(HPC cluster non-interactive queues prefer scripts.)

The question is: Does Ubuntu have the Environment Modules package?
 
Back
Top