Sunday, April 28, 2024
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 9823  / 1 Year ago, sat, december 31, 2022, 6:08:22

Is it valid to have "pointers" in /etc/environment using $FOO syntax? Right now my /etc/environment looks like this:



JAVA_HOME=/usr/lib/jvm/java-6-openjdk
MAVEN_HOME=/usr/bin/apache-maven/apache-maven-3.0.4
M2_HOME=$MAVEN_HOME
M2=$MAVEN_HOME/bin
PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$JAVA_HOME/bin:$MAVEN_HOME/bin


I'm not getting the results that I'm expecting though:



~$ echo $JAVA_HOME
/usr/lib/jvm/java-6-openjdk
~$ echo $MAVEN_HOME
/usr/bin/apache-maven/apache-maven-3.0.4
~$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin/bin:/usr/games:$JAVA_HOME/bin:$MAVEN_HOME/bin

More From » environment-variables

 Answers
6

I didn't find much documentation on /etc/environment, but the reason things don't work the way you expect is that it's "not a script file", and thus is not processed by the shell, so referencing a previously-defined variable doesn't work. This explains the behaviour you're seeing.



You're better off defining these kinds of environment variables in your home, in .profile or .bashrc, or if you need them for all users, in /etc/profile.d or /etc/bash.bashrc.



There's some pretty extensive documentation on setting environment variables here, and it points to either .profile or .bashrc as the preferred place to put this stuff.


[#37694] Saturday, December 31, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
coffekne

Total Points: 114
Total Questions: 122
Total Answers: 126

Location: Mauritania
Member since Sun, Oct 17, 2021
3 Years ago
;