0

I need to set some environment variables in Ubuntu. I do the following and it works:

export PATH="/home/vagrant/ns-allinone-2.35/bin:/home/vagrant/ns-allinone-2.35/tcl8.5.10/unix:/home/vagrant/ns-allinone-2.35/tk8.5.10/unix:$PATH"
export LD_LIBRARY_PATH="/home/vagrant/ns-allinone-2.35/otcl-1.14:/home/vagrant/ns-allinone-2.35/lib"
export TCL_LIBRARY="/home/vagrant/ns-allinone-2.35/tcl8.5.10/library"

But I move the same thing in a script envexport.sh and execute it, the environment variables are not getting set.

Where am I going wrong? How to accomplish this?

Thanks.

3 Answers 3

4

If you just run the script, the environment variables get destroyed when the script finishes.

Use . envexport.sh. That way the commands get executed in the current shell (environment).

Sign up to request clarification or add additional context in comments.

Comments

2

When you run a command in the shell, the shell creates a subprocess (child process). All the environment variables which were defined or changed down in the subprocess will be lost to the parent process.

However if you source a script, you force the script to run in the current process. That means environment variables in the script you ran will not be lost.

Comments

0

One thing that may help is if you will want those variables set for all of your sessions you can place the same commands in your .bashrc file by running the following command and pasting the lines in the file.

vim ~/.bashrc

and the run

source ~/.bashrc

in any terminals you currently are running. If you start any new terminals they will automatically have your directories added to your path.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.