从 .cshrc 获取 .bashrc

发布于 2024-09-13 04:15:59 字数 497 浏览 5 评论 0原文

是否可以在非交互式会话中从.cshrc获取.bshrc文件? 我这么问是因为 tcsh 是我们工作中的默认 shell,并且必须使用 .cshrc 来最初设置环境。
但是,我不太熟悉 tcsh,而且我在 bash 中有自己的设置,所以现在我的 .cshrc 文件末尾有以下几行:

if ( $?prompt && -x /bin/bash) then
  exec /bin/bash
endif

这工作正常,从 .bashrc 加载我的环境并给出我为交互式会话提供了 bash 提示符,但现在我还需要对非交互式会话进行相同的设置,例如通过 SSH 使用所有正确的路径等远程运行命令。
在这种情况下我无法使用“exec”,但我不知道如何切换到 bash 并“非交互式”加载 bash 配置文件。
我们所有的机器共享相同的主目录,因此对本地 *rc 文件的任何更改也会影响远程机器。

欢迎任何想法 - 感谢您的帮助!

Is it possible to source a .bshrc file from .cshrc in a non-interactive session?
I'm asking because tcsh is our default shell at work and the .cshrc has to be used to set up the environment initially.
However, I am not really familiar with the tcsh and I have my own set-up in bash, so right now I have the following lines at the end of my .cshrc file:

if ( $?prompt && -x /bin/bash) then
  exec /bin/bash
endif

This works fine, loading my environment from .bashrc and giving me a bash prompt for interactive sessions but now I also need the same set-up for non-interactive sessions, e.g. to run a command remotely via SSH with all the correct PATHs etc.
I can't use 'exec' in that case but I can't figure out how to switch to bash and load the bash config files "non-interactively".
All our machines share the same home directory, so any changes to my local *rc files will affect the remote machiens as well.

Any ideas welcome - thank you for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

谈情不如逗狗 2024-09-20 04:15:59

经过更多研究后,我现在非常确定这行不通,但当然请随时证明我错了!

要在 bash 中加载环境,我必须切换到 bash shell。即使这是可能的“在后台”,即没有得到提示,它仍然会破坏任何 tcsh 命令,然后尝试在 bash 下执行这些命令。

嗯嗯,回到绘图板......

After some more research I'm now quite sure that this won't work, but of course feel free to prove me wrong!

To load the environment in bash I have to switch to a bash shell. Even if that is possible "in the background", i.e. without getting a prompt, it would still break any tcsh commands which would then be attempted to execute under bash.

Hmmmm, back to the drawing board...

酒绊 2024-09-20 04:15:59

如果设置了$command,则有csh的参数,因此它是一个远程shell命令。这在 .cshrc 中对我有用:

if ($?command) then
  echo Executing non-interactive command in bash: $command $*
  exec /bin/bash -c "${command} $*"
endif
echo Interactive bash shell
exec bash -l

测试:

$ ssh remotehost set | grep BASH
BASH=/bin/bash
...

证明它在 Bash 中运行。

If $command is set there are arguments to csh, so it is a remote shell command. This works for me in .cshrc:

if ($?command) then
  echo Executing non-interactive command in bash: $command $*
  exec /bin/bash -c "${command} $*"
endif
echo Interactive bash shell
exec bash -l

Test:

$ ssh remotehost set | grep BASH
BASH=/bin/bash
...

proves that it ran in Bash.

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