从 .cshrc 获取 .bashrc
是否可以在非交互式会话中从.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过更多研究后,我现在非常确定这行不通,但当然请随时证明我错了!
要在 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...
如果设置了
$command
,则有csh
的参数,因此它是一个远程shell命令。这在.cshrc
中对我有用:测试:
证明它在 Bash 中运行。
If
$command
is set there are arguments tocsh
, so it is a remote shell command. This works for me in.cshrc
:Test:
proves that it ran in Bash.