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?

NagaLakshmi
  • 715
  • 3
  • 12
  • 24

1 Answers1

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