Nul*_*ser 46 rhel su environment-variables
例如,我有一个用户user1
对其 进行了修改.bash_profile
,其中一个更改了PATH
,例如:export PATH=/some/place:$PATH
。如果我user1
以su - user1
.
但是,如果我尝试通过su
as运行命令root
,例如:
su -c test.sh oracle
Run Code Online (Sandbox Code Playgroud)
(测试包含echo $PATH
)
它似乎没有修改PATH
(或 root 的PATH
,就此而言)。我也试过复制.bash_profile
到.profile
,无济于事。
为什么会这样?
Kev*_*vin 72
使用su
没有-l
或-
开始bash
作为一个互动的,但非登录shell,不从任何你指定的文件中读取。使用-l
or-
选项或将相关配置放入/root/.bashrc
.
配置文件的快速摘要:
-l
/ --login
)读/etc/profile
第一,然后它最先找到的:~/.bash_profile
,~/.bash_login
,和~/.profile
。 -i
) 读取/etc/bash.bashrc
和~/.bashrc
, 以该顺序(除非使用该--rcfile
选项并告诉它查看其他地方)。 -l
或-i
标志,读取BASH_ENV
环境变量中指定的文件。 sh
登录 shell运行时,它将按顺序读取/etc/profile
和~/.profile
。sh
交互式非登录运行时,它会读取ENV
.Bash 的行为取决于它是否认为它是登录 shell,即当您登录到系统时运行的第一个 shell。它仅.bash_profile
在它是登录外壳时读取。如果您将PATH
更改代码放入其中.bashrc
,它将为所有交互式 bash shell 运行,而不仅仅是登录 shell。