Saturday, May 18, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 23235  / 2 Years ago, fri, november 18, 2022, 10:27:47

Let's say I have an environment variable named JAVA_HOME, defined in /etc/environment file. I need to append a new value JAVA_HOME/bin in the PATH variable. Consider the following,



JAVA_HOME=/usr/apps/jdk1.8.10_1
PATH=/bin/something/:/bin/bash/something:/usr/apps/jdk1.8.10_1/bin


Now if you look at it, if I could replace /usr/apps/jdk1.8.10_1/bin, with something like below, it would be more convenient.



PATH=/bin/something/:/bin/bash/something:JAVA_HOME/bin


How could I do that? Is it %JAVA_HOME%/bin?


More From » bash

 Answers
7

You can't do that in /etc/environment. It's not a script file, and variable expansion does not work there.



To modify PATH system wide, a file with a .sh extension in the /etc/profile.d folder is a better method. It can be named myvars.sh or just about anything, as long as it has the .sh extension. In your case it might look something like this:



export JAVA_HOME=/usr/apps/jdk1.8.10_1
PATH="$PATH:$JAVA_HOME/bin"


That way you keep the default PATH definition in /etc/environment, and modify it in your own file.



Please see the EnvironmentVariables page for reference.


[#13708] Sunday, November 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
asketbridiculou

Total Points: 168
Total Questions: 116
Total Answers: 115

Location: Antigua and Barbuda
Member since Sat, Jan 28, 2023
1 Year ago
;