5

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!

2 Answers 2

4

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.

4
  • so, in short, just use /etc/profile :) Feb 1, 2012 at 20:07
  • 1
    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, 2012 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. Feb 6, 2012 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, 2012 at 23:31
1

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.

2
  • 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, 2010 at 14:58
  • I also tried this and it did not work.
    – benmccann
    Mar 27, 2011 at 18:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .