Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
so, in short, just use /etc/profile :) –  Filipe Pina Feb 1 '12 at 20:07
    
No, it just means variable substitution doesn't work when editing the global profile. /etc/profile is a per-user environment location. sometimes you really do want to edit the global environment settings. –  Dan Feb 1 '12 at 23:24
    
/etc/profile is per-user...? A per-user file in /etc? Last time I checked /etc/profile is the system-wide ~/.profile. ~/.profile is the per-user location. –  Filipe Pina Feb 6 '12 at 20:08
    
Sorry - misread your comment. I think /etc/profile is just for interactive shells, and I needed to handle non-interactive shells as well. –  Dan Feb 6 '12 at 23:31
add comment

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.

share|improve this answer
    
Thanks, but this didn't work in my environment (10.04 32-bit server). Same effect, where it seems to treat the value as a literal. –  Dan Jul 30 '10 at 14:58
    
I also tried this and it did not work. –  benmccann Mar 27 '11 at 18:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.