Setting a shell variable from within a script file...
Posted on 2002-03-12
I'm running Linux Mandrake 7.2 on a PC with the bash shell.
I would like to setup some variables in a shell script, so as to make these variables available to all subsequent shell commands.
Here is the shell script:
The shell script is stored in a file called setenv.sh. To run the shell script I type in the command ./setenv.sh
Now if after having typed that command, I type in the command echo $BEA_HOME, I get an empty line.
So clearly, the variable BEA_HOME has not been set. Or rather it has been set, but not exported outside of the script shell.
Then I add the line echo $BEA_HOME to the shell script, obtaining the following shell script:
Now running the shell script will display the variable.
But if I then type in the command echo $BEA_HOME after the execution of the shell script, I still get an empty line.
The variable is not exported to the current parent shell.
Then I removed the first line of the shell script, obtaining the following shell script:
And I got the same result. No better.
How could I export a variable to the current shell, from a shell script.