如何从 csh 脚本内部获取 bash 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5311463/
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-09-17 23:37:03  来源:igfitidea点击:

how to source a bash script from inside a csh script

bashscripting

提问by Arovit

  #!/bin/csh -x
   exec bash
   source ~arovit/RTM_test/unit_RTM/fail.10/failure.001.sh
   exec csh
   <script continues...>

is there any other way to do so ?

有没有其他方法可以做到这一点?

回答by Shawn Chin

If the whole purpose of the bash script is to export the relevant env variables, I'd suggest you run the script as bash, the call the following script using csh. E.g.:

如果 bash 脚本的全部目的是导出相关的 env 变量,我建议您将脚本作为 bash 运行,使用csh. 例如:

#!/bin/bash
source ~arovit/RTM_test/unit_RTM/fail.10/failure.001.sh
csh -x your_csh_script.sh

If the bash script isn't exporting vars, and is simply performing some tasks, then do it the other way round:

如果 bash 脚本没有导出变量,而只是在执行一些任务,那么反过来做:

#!/bin/csh -x
bash ~arovit/RTM_test/unit_RTM/fail.10/failure.001.sh
<script continues...>

回答by estani

Just do this:

只需这样做:

#!/bin/csh
bash -c 'source bash_source; exec csh'