简体   繁体   English

bash脚本:采购tcsh脚本

[英]bash scripting: sourcing tcsh script

I need to source a tcsh script from my bash script. 我需要从我的bash脚本中获取tcsh脚本。 I have tried to do it like this: 我试图这样做:

tcsh -c "source ~/test.tcsh"

The problem with this command is that $_ is empty inside of the sourced tcsh script. 此命令的问题在于$_在源tcsh脚本中为空。 Any ways to deal with that? 有什么办法可以解决?

Thanks in advance! 提前致谢!

The source command runs the script in the current shell. source命令在当前shell中运行脚本。 tcsh -c "source ~/test.tcsh" sources the file test.tcsh in the shell running the source command, which is an instance of tcsh , not the bash shell that runs tcsh . tcsh -c "source ~/test.tcsh"在运行source命令的shell中提供文件test.tcsh ,该命令是tcsh的实例,而不是运行tcshbash shell。 You aren't going to be able to execute a tcsh script in any way that affects the environment of the current bash shell. 您将无法以任何会影响当前 bash shell环境的方式执行tcsh脚本。 You could start a new bash shell that inherits from an instance of tcsh which was so modified, with something like 您可以启动一个新的bash shell,该shell继承自经过修改的tcsh实例,其内容类似于

tcsh -c 'source ~/test.tcsh; bash'

but that may not be what you need. 但这可能不是您所需要的。 For instance, 例如,

tcsh -c 'source ~/test.tcsh; bash'
echo "OK, we're back"

will leave you in an interactive bash shell, but you won't see "OK, we're back" until after you exit that shell, which will cause tcsh to exit and return control to the original. 会将您留在交互式bash shell中,但是直到您退出该shell之后,您才会看到“ OK,我们回来了”,这将导致tcsh退出并将控制权返回到原始状态。

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

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