Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using Ubuntu 9.10 (karmic). And, my ~/.pam_environment looks like the following.

PATH            DEFAULT=${PATH}:~/Adobe/Reader9/bin:~/texlive/2009/bin/x86_64-linux
GIT_EDITOR      DEFAULT=vim
MANPATH         DEFAULT=${MANPATH}:~/texlive/2009/texmf/doc/man
INFOPATH        DEFAULT=${INFOPATH}:~/texlive/2009/texmf/doc/info

But, echo $PATH returns me duplicated entries as the following.

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:~/Adobe/Reader9/bin:~/texlive/2009/bin/x86_64-linux:~/Adobe/Reader9/bin:~/texlive/2009/bin/x86_64-linux

I've tried replacing DEFAULT by OVERRIDE in my ~/.pam_environment file. But, that didn't help.

Does any one know what's wrong with my ~/.pam_environment?

share|improve this question
1  
Not directly related, but ~ won't work in there. If you had set it from the shell it would have been expanded properly, but pam_env doesn't know how to expand it. Use ${HOME} instead. –  geekosaur Mar 15 '11 at 19:45

3 Answers 3

The problem seems to stem from the fact that pam_env defaults to reading the user ~/.pam_environment every time it is invoked. A lot of login methods (cron, lightdm, lightdm-autologin, login, sshd and su on my machine) invoke pam_env twice: once to read the /etc/environment and ~/.pam_environment files, and once to read the /etc/default/locale file. In neither case is the user_readenv flag set, so pam_env reads, and acts on, your ~/.pam_environment twice.

To fix this, go to your /etc/pam.d directory, and add the following to every line in which pam_env is invoked with the envfile=/etc/default/locale option:

user_readenv=0
share|improve this answer

Check your /etc/pam.d/ that pam_env.so isn't loaded twice somehow, such as both in session and in auth.

share|improve this answer
    
Which file should I examine in /etc/pam.d? –  reprogrammer May 27 '10 at 21:54
    
It looks like pam_env.so is actually loaded in both auth and session. See the output of "grep "pam_env *" in /etc/pam.d at filedropper.com/etc-pamd. What can I do about this duplication? –  reprogrammer May 27 '10 at 22:07
    
That URL doesn't exist (anymore?). Please post the information here. –  Peter Eisentraut Jun 1 '10 at 6:51

Not an answer, exactly, but possibly useful to others who have duplication issues


Starting from the accept answer I received on from Stack Overflow: How do I manipulate $PATH elements in shell scripts? I have developed a slightly large set of tools. Most of the credit here should go to Jonathan Leffler who provided the model I used in writing these.

Add without duplicating

# Insure that a path element exists by adding it to the end if it does not
#
#   $1 name of the shell variable to set (e.g. PATH)
#   $3 the path element that we want to insure exists
function insure_path () {
    local path=$1
    local list=$(eval echo '$'$path)
    local pat=$2

    checkstr=$(echo "$list" | tr ":" "\n" | grep -Fm 1 "$pat")
    if [ "$checkstr" ] 
    then
        true
    else
        export $path=$(echo $list:$pat | sed -e 's|\(:\):*|\1|g' -e 's|:$||' -e'
s|^:||')
    fi
}

# Insure that a path element exists by adding it to the front if it does not
#
#   $1 name of the shell variable to set (e.g. PATH)
#   $2 the path element that we want to insure exists
function insure_path_front () {
    local path=$1
    local list=$(eval echo '$'$path)
    local pat=$2

    checkstr=$(echo "$list" | tr ":" "\n" | grep -Fm 1 "$pat")
    if [ $checkstr ] 
    then
        true
    else
        export $path=$(echo $pat:$list | sed -e 's|\(:\):*|\1|g' -e 's|:$||' -e'
s|^:||')
    fi
}

Remove existing duplicates

# Remove duplicates from a path. Preferes the ealiest instance of each
# duplicate because this preserves the semantics of the existing path
#
#   $1 name of the shell variable to set (e.g. PATH)
function unduplicate_path () {
    local path=$1
    local list=$(eval echo '$'$path)
    local split_list=$(echo "$list" | tr ":" " ")
    local tempp=""
    # Build the new version of $path from scrath
    for p in $split_list
    do
        insure_path_back tempp $p
    done
    # Now replace the existing version
    export $path=$tempp
}
share|improve this answer

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.