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:
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.
. 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.