Nul*_*ser 46 rhel su environment-variables
例如,我有一个用户user1对其 进行了修改.bash_profile,其中一个更改了PATH,例如:export PATH=/some/place:$PATH。如果我user1以su - user1.
但是,如果我尝试通过suas运行命令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,不从任何你指定的文件中读取。使用-lor-选项或将相关配置放入/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。