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?
-
1There is no such thing as a "system-wide environment variable". They only exist per process.Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2014-07-04 05:55:58 +00:00Commented Jul 4, 2014 at 5:55
-
This might be useful: stackoverflow.com/questions/1464253/…nil– nil2014-07-04 05:58:55 +00:00Commented Jul 4, 2014 at 5:58
Add a comment
|
1 Answer
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?
2 Comments
NagaLakshmi
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?
sestus
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