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?
/bin/sh
is on Alpine but, traditionally,/etc/profile
is only sourced for login shells (i.e.su --login
orsu -
) – steeldriver Nov 05 '18 at 13:19/etc/profile
. It's much better to create a shell init file in/etc/profile.d
and make it executable. – Nasir Riley Nov 05 '18 at 14:43~/.profile
for user dev? Are you usingsu - dev
? – Nov 05 '18 at 15:40