bash - 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."
解决方案
您在这里要求“将一种语言嵌入另一种语言”,正如@Bayou 已经解释的那样,不直接支持。也许你被 HTML 世界宠坏了,你可以在其中使用 CSS 和 Javascript,也可以使用一些服务器端 PHP 或 Ruby 的东西。
与此最接近的是 HERE 文档。如果您在 bash 脚本中编写
csh <<CSH_END
your ...
csh ....
commands ...
go here ...
CSH_END
这些命令在由 csh 驱动的子进程中执行。它以相同的方式与 bash 一起工作。确保终止符(在我的示例中为 CSH_END)从第 1 列开始。
我不能说这是否适用于您的应用程序,因为在原始脚本中在同一进程中运行的东西现在在不同的进程中运行。
推荐阅读
- node.js - 在 Windows 10 上从 nodejs 调用 processing-java
- javascript - 如何获取从 settimeout 调用的函数的返回值
- python - 得到
在 Python 上向 Telegram 发送包含加号“+”的字符串时 - r - 使用 R,RStudio Knit to HTML,如何包含“内联”外部 HTML 文档块?
- sql - SQL Server mm/dd/yy 或 yy/dd/mm 或其他什么的 T-SQL 日期数据类型格式?
- python - Xarray 在时间变量中改变单位
- vue.js - 当我编辑从另一个字典克隆的数组中的字典时,所有重复的字典值也会更改
- intellij-idea - IntelliJ 中的 Test 文件夹在哪里
- javascript - Discord.JS 反应角色
- html - 如何动态更改导航栏链接的css内容