Results 1 to 3 of 3

Thread: [solved]issues adding environmental variables to /etc/environmental

  1. #1
    Join Date
    Mar 2008
    Beans
    65

    [solved]issues adding environmental variables to /etc/environmental

    Hi all,
    I'd like to create a script that adds some environmental variables from a file "variables" to /etc/environment

    The file "variables" is of the form

    Code:
    #!/bin/sh
    export ROOT=/opt/drivers
    export ROOT2=$ROOT/S56
    ....
    My idea was to add the "variables" file to /etc/environmental

    Code:
    sudo sh -c "cat  variables  >> /etc/environment"
    The problem with this approach is that if I
    Code:
    echo $ROOT2
    I get
    Code:
    $ROOT/S56
    rather than the expected
    Code:
    /opt/drivers/S56
    However, if from the terminal I run
    Code:
    source variables
    then if I
    Code:
    echo $ROOT2
    I get the expected result
    Code:
    /opt/drivers/S56

    How can I solve this issue?

    I could manually change the "variables" file to
    Code:
    #!/bin/sh
    export ROOT=/opt/drivers
    export ROOT2=${ROOT}/S56
    ....

    but the "variables" file might change in the future and is not me who creates it, so I need a more "automatic solution".

    Any help would be much appreciated!
    Last edited by santiagorf; April 12th, 2013 at 03:07 AM. Reason: solved

  2. #2
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: issues adding environmental variables to /etc/environmental

    I guess /etc/environment just doesn't get sourced by any shell script on Ubuntu anymore. On Debian, it's still sourced from /etc/init.d/kbd, but Ubuntu uses upstart. Try
    Code:
    grep /etc/environment /etc/init/*.conf
    Previously, it was used for locale settings and got sourced from /etc/init/mountall.conf. But it's deprecated in that role nowadays and /etc/default/locale gets sourced by /etc/init/mountall.conf instead.

    /etc/environment still gets evaluated by PAM module pam_env(8), but it's a C program that expects variables in /etc/environment to be simple KEY=VALUE pairs on separate lines.

    community/EnvironmentVariables#System-wide_environment_variables recommends placing your system-wide environment variables in /etc/profile.d/envvar.sh

    Also see this thread on debian-devel and manual page for pam_env.conf(5).
    Last edited by schragge; April 10th, 2013 at 05:56 PM.

  3. #3
    Join Date
    Mar 2008
    Beans
    65

    Re: issues adding environmental variables to /etc/environmental

    Thanks. That seemed to solve the problem!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •