You are not logged in.

#1 2022-01-15 17:41:21

beroal
Member
From: Ukraine
Registered: 2009-06-07
Posts: 325
Website

PATH in a clean environment

I wonder where these directories in the `PATH` variable come from. Different for different shells. They don't come from the environment since the environment is empty. Are they baked into executables? `/usr/ucb` is interesting.

[root@beroal /]# groupadd --gid=1005 test1
[root@beroal /]# useradd --gid=1005 --no-create-home --home-dir / --uid=1005 test1
[root@beroal /]# sudo -u test1 env -i /usr/bin/bash --norc --noprofile
bash-5.1$ env
PWD=/
SHLVL=1
_=/usr/bin/env
bash-5.1$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/bin
bash-5.1$ exit
[root@beroal /]# sudo -u test1 env -i /usr/bin/dash
$ env
PWD=/
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ 
[root@beroal /]# sudo -u test1 env -i /usr/bin/ksh
$ env
_=*56432*/bin/env
COMP_KEY=0
COMP_POINT=0
COMP_TYPE=0
PWD=/
SHLVL=1
A__z=F*COMP_KEY=F*COMP_POINT=F*COMP_TYPE="*SHLVL
$ echo $PATH

$ 
[root@beroal /]# sudo -u test1 env -i /usr/bin/zsh
beroal% env
HOME=/
LOGNAME=subroot
SHLVL=1
PWD=/
OLDPWD=/
_=/bin/env
beroal% echo $PATH
/bin:/usr/bin:/usr/ucb:/usr/local/bin
beroal%

we are not condemned to write ugly code

Offline

#2 2022-01-15 18:31:04

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,522
Website

Re: PATH in a clean environment

BASH:
See line 495 of variables.c which uses a constant defined on line 66 of config-top.h to set the PATH variable if it is not yet set.

I'm sure all the others use similar mechanisms.  You can also run `strings` on the binary itself and extract these paths, e.g.:

strings /bin/bash | grep sbin

Last edited by Trilby (2022-01-15 18:31:50)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB