如何让 GNU 屏幕读取 .bash_profile/.bash_rc 更改?

发布于 2024-11-27 17:28:12 字数 220 浏览 1 评论 0原文

.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青巷忧颜 2024-12-04 17:28:12

如果您希望 screen 始终将您的 shell 视为登录 shell,并获取与正常启动新 shell 时读取的文件相同的文件,请将以下内容添加到 ~/.screenrc (或者可能 < code>~/.byobu/.screenrc,如评论中指出的):

shell -$SHELL

这样,您不需要在每次启动新屏幕时手动告诉它获取文件。但如果您刚刚进行了更改并希望这些更改反映在当前屏幕中,则必须这样做。

有关此内容的文档(以及许多其他屏幕详细信息)可以在此处< /a>.基本上,shell 是一个屏幕命令,告诉它在需要创建新 shell 时运行以下命令。 $SHELL 是保存您首选 shell 路径的常用变量。 $SHELL 前面的破折号 - 表示它应该作为登录 shell 运行(这通常意味着它会获取您的 ~/.bash_profile代码>等)。

然而,值得指出的是,screen 默认只从启动 screen 的 shell 继承大多数环境变量;并且登录子 shell 可能会以意想不到的方式更改某些环境变量。我遇到了一种情况,我的 $PATH 元素基本上被排列了。感谢超级用户的这个特别出色的答案,我解决了这个问题。

您可能会注意到 source 命令可用。需要注意的是,这源自 screen 命令文件,而不是 shell 命令。其他相关(屏幕)命令包括 evalexec

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):

shell -$SHELL

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 of screen commands, rather than shell commands. Other relevant (screen) commands include eval and exec.

落叶缤纷 2024-12-04 17:28:12

您必须在打开的每个屏幕中执行此操作,因为它们都是不同的 shell。如果每次打开新 shell 时都需要进行更改,我建议您将更改放在 ~/.bashrc 中。

显然,您可以使用 此语法

C-a :
at "#" stuff "source ~/.bash_profile^M"

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:

C-a :
at "#" stuff "source ~/.bash_profile^M"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文