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?
Asked
Active
Viewed 5,866 times
2
-
1There is no such thing as a "system-wide environment variable". They only exist per process. – Ignacio Vazquez-Abrams Jul 04 '14 at 05:55
-
This might be useful: http://stackoverflow.com/questions/1464253/global-environment-variables-in-a-shell-script – nil Jul 04 '14 at 05:58
1 Answers
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?

sestus
- 1,875
- 2
- 16
- 16
-
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? – NagaLakshmi Jul 04 '14 at 06:01
-
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 – sestus Jul 04 '14 at 06:11