问题原文
原帖链接 · Iain Hallam · CC BY-SA 3.0
I've just spun up a brand new CentOS 7 VM (bash version 4.2.46) with Vagrant using the centos/7 box, and when I'm logged in as the vagrant user, this is my PATH:
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vagrant/.local/bin:/home/vagrant/bin
When logged in as root, here's the PATH:
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
I know that /etc/profile is adding /usr/local/sbin:/usr/sbin (at the end for most users, at the start for root), and the /etc/skel/.bash_profile that ends up in the vagrant home directory is adding /home/vagrant/.local/bin:/home/vagrant/bin, but where is the initial setting coming from?
At present I have no explanation of why users end up with /usr/local/bin:/usr/bin in their PATH, and root gets the others.
(Frankly, the ordering of the root PATH seems very odd, given that /usr/local/sbin and /usr/sbin should be at the end, according to /etc/profile.)
已采纳解答
原帖链接 · Schrute · CC BY-SA 3.0
In the bash source "config-top.h" has this:
/* The default value of the PATH variable. */
#ifndef DEFAULT_PATH_VALUE
#define DEFAULT_PATH_VALUE \
"/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:."
#endif
/* The value for PATH when invoking `command -p'. This is only used when
the Posix.2 confstr () function, or CS_PATH define are not present. */
#ifndef STANDARD_UTILS_PATH
#define STANDARD_UTILS_PATH \
"/bin:/usr/bin:/sbin:/usr/sbin:/etc:/usr/etc"
#endif
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
