开发者

source .bashrc from .cshrc

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 m开发者_如何学Pythony .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!


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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜