Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I have one common function called SetEnv in a file called SetEnv.

File SetEnv:

export PATH=$PATH:$JAVA_HOME/bin



echo $PATH

While running ./, I cannot see the updated path.

Please help how to solve this.

share|improve this question
That is not how you set an environmental variable. – bodhi.zazen Oct 8 '13 at 19:05

1 Answer 1

That's because when you run a script from terminal, this doesn't run in the current shell terminal, but in a subshell. The variables, functions and aliases created in this subshell are only known to the particular bash session of that subshell. When that shell exits and the parent regains control, everything is cleaned up and all changes to the state of the shell made by the script, are forgotten.

To prevent this, you can source the script in the current shell terminal, using the following command:


or, simple:

.          #dot, space and the path to the script

Also, your should look like:


source /path/to/SetEnv  #if you want that your script to know about 'SetEnv' function.


echo $PATH

More about:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.