Results 1 to 3 of 3
I have a vendor-provided shell script that I'm executing in Korn shell. It simply sets some environment variables. The variables that are set do not remain persistent outside of the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-30-2012 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 14
global environment variables
I have a vendor-provided shell script that I'm executing in Korn shell. It simply sets some environment variables. The variables that are set do not remain persistent outside of the script. So I decided to do some testing by creating a simple script. The contents of df.sh are:
export MY_DIR=/apps/inserver6
I change the permissions on the file so that it can be executed, then execute it. However, the following results in null output:
echo $MY_DIR
What am I missing? Any help would be greatly appreciated.
Thanks,
Dave
- 10-30-2012 #2
The variable MY_DIR is set in the context of that script´s process.
And it is confined to it.
So you call the script, a process is created, the variable gets set and then the script ends and the process dies.
And with it the variable.
To set variables for the current process, you need to source that script.
In bash, this can be done with the dot command.
In korn shell it is probably also the dot command, but in doubt consult the man page.Code:. df.sh
You must always face the curtain with a bow.
- 10-30-2012 #3Just Joined!
- Join Date
- Mar 2008
- Posts
- 14
Got it. Instead of this:
./df.sh
I had to run this:
. ./df.sh


Reply With Quote
