Can you use variables when editing /etc/environment in ubuntu 10.04?
I'm trying to introduce a variable and add it to the global path in ubuntu 10.04. According to the official docs, /etc/environment is the right place. Here's what my example looks like:
GRADLE_HOME=/etc/gradle-0.9-preview-3
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$GRADLE_HOME/bin"
The GRADLE_HOME variable is added to the environment, but it's not interpreting the $GRADLE_HOME variable during the PATH assignment. Hard-coding it works fine. Not a big deal, but I'd like to know if variable substitution is supported, or if there's a better way to do this? Thanks!
Solution 1:
This explanation from a related post appears to provide the answer:
Because /etc/environment is not a shell script. It is the shell that does expansion of environment variables. The PAM module pam_env is what reads /etc/environment - and it treats it as a simple list of KEY=VAL pairs and sets up the environment accordingly. It has no language for doing variable expansion.
Solution 2:
Read the pam_env.conf(5) manpage.
I believe you need to add curly-braces around the variable name on the right-hand side:
GRADLE_HOME=/etc/gradle-0.9-preview-3
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${GRADLE_HOME}/bin"
(Possibly non-existent) environment variables may be used in values using the ${string} syntax and (possibly non-existent) PAM_ITEMs may be used in values using the @{string} syntax. Both the $ and @ characters can be backslash escaped to be used as literal values values can be delimited with "", escaped " not supported. Note that many environment variables that you would like to use may not be set by the time the module is called. For example, HOME is used below several times, but many PAM applications don´t make it available by the time you need it.