Linux 更改 /etc/profile 后,我需要做什么来重置我的 shell?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4642924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:06:55  来源:igfitidea点击:

After changing /etc/profile, what do I have to do to reset my shell?

linuxunix

提问by TIMEX

To test its effects immediately instead of having to reload the terminal

立即测试其效果,而不必重新加载终端

采纳答案by Serdar Dalgic

use source /etc/profile

source /etc/profile

for details, man source or you can checkout this link http://bash.cyberciti.biz/guide/Source_command

有关详细信息,请参考人源,或者您可以查看此链接http://bash.cyberciti.biz/guide/Source_command

回答by sjr

If this is bash you can do . /etc/profile, it's the same as doing source /etc/profile.

如果这是您可以执行的 bash . /etc/profile,则与执行source /etc/profile.

回答by Jonathan Leffler

As sjrsays, you can approximate the effect of the change by re-reading /etc/profileusing the dot .(or, in Bash, source) command.

正如sjr所说,您可以通过/etc/profile使用点.(或在 Bash 中,source)命令重新阅读来近似更改的效果。

However, you need to be aware that /etc/profilegets to work with a more minimal starting environment, so the effect you get by rereading the profile is not necessarily identical to the effect you get on login. You can simulate the original environment more accurately using the envcommand to unset the environment. With bash, you can use the -loption to make the shell behave more like a login shell - in conjunction with env, you can simulate the login environment accurately:

但是,您需要注意,/etc/profile使用更小的起始环境开始工作,因此您通过重新阅读配置文件获得的效果不一定与您在登录时获得的效果相同。您可以使用env取消设置环境的命令更准确地模拟原始环境。使用bash,您可以使用-l选项使 shell 的行为更像登录 shell - 结合env,您可以准确地模拟登录环境:

env -i HOME=$HOME PATH=/bin:/usr/bin USER=$USER ... bash -l