2

I've added a system wide environment variable in /etc/environment. I want to access this variable in a bash script. Is there any way to access it?

2
  • 1
    There is no such thing as a "system-wide environment variable". They only exist per process. Commented Jul 4, 2014 at 5:55
  • This might be useful: stackoverflow.com/questions/1464253/… Commented Jul 4, 2014 at 5:58

1 Answer 1

4

Assuming that PATH is an environmental variable, also in /etc/environment, I can access path in a script like this:

#!/bin/sh


echo $PATH

So what's wrong with your variable?

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

2 Comments

I was able to print the path in my bash script.But the new variable I set recently is not reflecting in the script.Do I need a system reboot to take effect?
Ok thats something different. It's like exporting PATH into "something" in a bash session. The changes last only for this session. If you want to change the value of the PATH permantly, your script may need to edit /etc/environment (or do some export in .bashrc and then source .bashrc). Hope it helps

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.