首页 > 解决方案 > How can I invoke both BASH and CSH shells in a same script

问题描述

In the same script, I want to use some CSH commands and some BASH commands. Invoking one after the other giving me problems despite I am following the different syntax for respective shells. I want to know where is mistake in my code Your suggestions are appreciated!!

I am a beginner to shell, especially so for CSH. but the code I got has been written in CSH entirely. Since I have some familiarity with CSH, I wanted to tweak the existing CSH code by including BASH commands, which I am comfortable using it. When I tried BASH commands after CSH by invoking !#/bin/bash, it is giving some errors. I want to know if I am missing any options!!

#!/bin/csh
----
----
----
#!/bin/bash
dir2in="/nethome/achandra/NCEI/CCSM4_Historical/Forecasts"
filin2 ="ccsm4_0_cfsrr_Fcst.${ENS}.cam2.h1.${yyear[${iimonth}]}-${mmon[${iimonth}]}-${ssday}-00000.nc"
cp $dirin/$filin /nethome/achandra/NCEI/CCSM4_Historical_Forecasts/
ln -s /nethome/achandra/NCEI/CCSM4_Historical/Forecasts/$filin /nethome/achandra/NCEI/CCSM4_Historical_Forecasts/"${$filin%.nc.cdo}.nc"
#!/bin/csh 

I am getting errors such as "dirin: Undefined variable."

标签: bashshellinvokecsh

解决方案


您在这里要求“将一种语言嵌入另一种语言”,正如@Bayou 已经解释的那样,不直接支持。也许你被 HTML 世界宠坏了,你可以在其中使用 CSS 和 Javascript,也可以使用一些服务器端 PHP 或 Ruby 的东西。

与此最接近的是 HERE 文档。如果您在 bash 脚本中编写

csh <<CSH_END
your ...
csh ....
commands ...
go here ...
CSH_END

这些命令在由 csh 驱动的子进程中执行。它以相同的方式与 bash 一起工作。确保终止符(在我的示例中为 CSH_END)从第 1 列开始。

我不能说这是否适用于您的应用程序,因为在原始脚本中在同一进程中运行的东西现在在不同的进程中运行。


推荐阅读