如何让 GNU 屏幕读取 .bash_profile/.bash_rc 更改?
在 .bash_rc
或 .bash_profile
中进行更改后,当我启动 GNU 屏幕时,它无法识别这些更改。 我可以
source ~/.bash_profile
,它适用于我打开的当前屏幕窗口,但我必须对我打开的每个屏幕窗口执行此操作。
如何让屏幕读取 bash 配置中的最新更改?
After I make changes in .bash_rc
or .bash_profile
, when I start GNU screen, it doesn't recognize those changes.
I can
source ~/.bash_profile
and it works for the current screen window I have open, but I have to do that for every screen window I have open.
How do I get screen to read my latest changes in my bash configuration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望 screen 始终将您的 shell 视为登录 shell,并获取与正常启动新 shell 时读取的文件相同的文件,请将以下内容添加到
~/.screenrc
(或者可能 < code>~/.byobu/.screenrc,如评论中指出的):这样,您不需要在每次启动新屏幕时手动告诉它获取文件。但如果您刚刚进行了更改并希望这些更改反映在当前屏幕中,则必须这样做。
有关此内容的文档(以及许多其他屏幕详细信息)可以在此处< /a>.基本上,
shell
是一个屏幕命令,告诉它在需要创建新 shell 时运行以下命令。$SHELL
是保存您首选 shell 路径的常用变量。$SHELL
前面的破折号-
表示它应该作为登录 shell 运行(这通常意味着它会获取您的~/.bash_profile
代码>等)。然而,值得指出的是,screen 默认只从启动 screen 的 shell 继承大多数环境变量;并且登录子 shell 可能会以意想不到的方式更改某些环境变量。我遇到了一种情况,我的 $PATH 元素基本上被排列了。感谢超级用户的这个特别出色的答案,我解决了这个问题。
您可能会注意到
source
命令可用。需要注意的是,这源自screen
命令文件,而不是 shell 命令。其他相关(屏幕)命令包括eval
和exec
。If you want screen to always treat your shell as a login shell, and source the same files that would be read if just started a new shell normally, add the following to
~/.screenrc
(or maybe~/.byobu/.screenrc
, as pointed out in the comment):This way, you don't need to manually tell it to source your files each time you start a new screen. Though you would have to if you just made changes and wanted those changes to be reflected in your current screen.
The documentation for this (and lots of other screen details) can be found here. Basically,
shell
is a command to screen telling it to run the following when it needs to create a new shell.$SHELL
is the usual variable holding the path to your preferred shell. And the dash-
in front of$SHELL
indicates that it should be run as a login shell (which will typically mean it sources your~/.bash_profile
, etc.).It's worth pointing out, however, that screen defaults to just inheriting most environment variables from the shell where you start screen; and a login sub-shell may alter some environment variables in unexpected ways. I ran into a situation where elements of my $PATH were basically permuted. I solved the problem thanks to this particularly excellent answer on superuser.
You may notice the
source
command available. It's important to note that this sources a file ofscreen
commands, rather than shell commands. Other relevant (screen) commands includeeval
andexec
.您必须在打开的每个屏幕中执行此操作,因为它们都是不同的 shell。如果每次打开新 shell 时都需要进行更改,我建议您将更改放在 ~/.bashrc 中。
显然,您可以使用 此语法:
You have to do it in each screen that you have open since they are all different shells. If you need the change every time a new shell is opened, I suggest you put the changes in ~/.bashrc instead.
Apparently, you can send a command to all windows at once using this syntax: