Linux 从 bash 运行 csh 脚本,通过命令临时更改 shell

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4132661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:54:37  来源:igfitidea点击:

run csh scripts from bash, change shell temporary via command

linuxbashtcsh

提问by user501743

I need to run csh scripts from a bash shell and therefore temporary change to tcsh via a command. It works perfect in interactive mode but i cant figure out in a one line command. So in interactive mode i do in the bash shell:

我需要从 bash shell 运行 csh 脚本,因此需要通过命令临时更改为 tcsh。它在交互模式下工作完美,但我无法在一行命令中弄清楚。因此,在交互模式下,我在 bash shell 中执行以下操作:

tcsh

tcsh

source my.tcshr

源 my.tcshr

useMyTcshCmd

使用MyTcshCmd

etc.

等等。

How can i do all of this in 1 command? Sorry for the newbie question...

我怎样才能在 1 个命令中完成所有这些?对不起,新手问题...

采纳答案by Tometzky

tcsh -c "echo foo; echo bar"

Result:

结果:

foo
bar

So this should work:

所以这应该有效:

tcsh -c "source my.tcshr; useMyTcshCmd"

回答by ?imon Tóth

You should specify the interpreter directly in the script:

您应该直接在脚本中指定解释器:

#!/usr/bin/tcsh
echo "doing stuff"

And then simply run the script:

然后只需运行脚本:

./script

回答by Raghuram

tcsh -c useMyTcshCmd