简体   繁体   English

来自.cshrc的源.bashrc

[英]source .bashrc from .cshrc

Is it possible to source a .bshrc file from .cshrc in a non-interactive session? 是否可以在非交互式会话中从.cshrc 导出.bshrc文件? I'm asking because tcsh is our default shell at work and the .cshrc has to be used to set up the environment initially. 我问是因为tcsh是我们工作时的默认外壳,而.cshrc必须首先用于设置环境。
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: 但是,我对tcsh并不是很熟悉,我在bash中有自己的设置,因此,现在我的.cshrc文件末尾有以下几行:

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, eg to run a command remotely via SSH with all the correct PATHs etc. 可以正常工作,从.bashrc加载我的环境并为交互式会话提供bash提示,但是现在我也需要为非交互式会话设置相同的设置,例如,通过SSH使用所有正确的PATH等远程运行命令。
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". 在这种情况下,我不能使用“ exec”,但是我无法弄清楚如何切换到bash并“非交互地”加载bash配置文件。
All our machines share the same home directory, so any changes to my local *rc files will affect the remote machiens as well. 我们所有的机器都共享相同的主目录,因此对本地* rc文件的任何更改也会影响远程机器。

Any ideas welcome - thank you for your help! 欢迎任何想法-谢谢您的帮助!

If $command is set there are arguments to csh , so it is a remote shell command. 如果设置了$commandcsh有参数,因此它是一个远程shell命令。 This works for me in .cshrc : 这适用于我在.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. 证明它在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. 要在bash中加载环境,我必须切换到bash shell。 Even if that is possible "in the background", ie without getting a prompt, it would still break any tcsh commands which would then be attempted to execute under bash. 即使“在后台”也有可能,即没有提示,它仍然会中断任何tcsh命令,然后尝试在bash下执行。

Hmmmm, back to the drawing board... 嗯,回到画板...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM