1

I added a new user dev on my Alpine based image. After switching to the new user I see env variables are different in case of both root and dev user. Specially $PATH variable is different. But I think it should not be different as it is exported globally on /etc/profile.

$ cat /etc/profile

export CHARSET=UTF-8
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PAGER=less
export PS1='\h:\w\$ '
umask 022

for script in /etc/profile.d/*.sh ; do
        if [ -r $script ] ; then
                . $script
        fi
done
composer(){ su-exec deploy composer.phar "$@"; }

$PATH variable in case of root user

# env | grep $PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

$PATH variable in case of dev

# adduser -D -u 2500 -s /bin/sh dev
# su dev
$ env | grep $PATH
PATH=/bin:/usr/bin

I know I can add .sh inside profile.d dir and export the $PATH variable again, but why it is not inheriting as per this question (If processes inherit the parent's environment, why do we need export?)? Is there any other way I can inherit the env variables except creating a new profile for dev user ? Where those env variables has been set for dev user?

4
  • Are you asking why it is not inheriting, or why it is not getting set? (You may be using some technical words incorrectly) Please show process, so that we can see what you are trying to do. Nov 5, 2018 at 13:19
  • 3
    I'm not sure what /bin/sh is on Alpine but, traditionally, /etc/profile is only sourced for login shells (i.e. su --login or su -) Nov 5, 2018 at 13:19
  • In addition to what has been said, it's best not to do what you're trying to do via /etc/profile. It's much better to create a shell init file in /etc/profile.d and make it executable. Nov 5, 2018 at 14:43
  • Is there a ~/.profile for user dev? Are you using su - dev ?
    – user232326
    Nov 5, 2018 at 15:40

0

You must log in to answer this question.