简体   繁体   English

将bash命令重构为tcsh命令

[英]Refactoring bash command into tcsh command

I have problem with refactoring bash command into tcsh-friendly command. 我在将bash命令重构为tcsh-friendly命令时遇到问题。 Don't know the tcsh syntax very well so the error im receiving doens't give me any clue. 我不太了解tcsh语法,因此收到的错误不会给我任何提示。

The whole bash script was about adding modules on server 整个bash脚本是关于在服务器上添加模块

MODULEPATH=/app/modules/0/modulefiles:/env/common/modules
export MODULEPATH
module() { eval `/app/modules/0/bin/modulecmd sh "$@"` ;} 

I changed first two commands to tcsh already 我已经将前两个命令更改为tcsh

setenv MODULEPATH /app/modules/0/modulefiles:/env/common/modules
set MODULEPATH

But i dont know how to change the syntax of last command. 但是我不知道如何更改上一个命令的语法。 Console is returning me error "Badly placed ()'s.". 控制台向我返回错误“放置不正确()。”。

Can I ask for little lesson what to change in this command to be tcsh-friendly? 我可以要求一点教训,以便对tcsh友好地更改此命令吗?

chepner is right saying tcsh doesn't have functions at all and you'd have to write an alias instead. chepner说的对, tcsh根本没有功能, 您必须写一个别名。 That's not much of an effort for your one-line function: 对于单行函数来说,这并不是什么大的工作:

alias module 'eval `/app/modules/0/bin/modulecmd sh \!*`'

Basically, we prepend alias , remove () and {} , quote and replace "$@" with \\!* . 基本上,我们在alias ,删除(){} ,引用并用\\!*替换"$@"

The module command you want to port from bash to tcsh already comes with an initialization file to the tcsh shell. 您想要从bash移植到tcsh的module命令已经带有一个初始化文件到tcsh shell。 For all shells or scripting languages module is compatible with, there is an initialization file provided in the init directory of the software. 对于所有与Shell或脚本语言兼容的module ,该软件的init目录中提供了一个初始化文件。

So from your example, Modules is installed in /app/modules/0 , so you should have a /app/modules/0/init directory and a /app/modules/0/init/tcsh script to initialize the module command for tcsh. 因此,根据您的示例,模块安装在/app/modules/0 ,因此您应该具有/app/modules/0/init目录和/app/modules/0/init/tcsh脚本来初始化/app/modules/0/init/tcsh的module命令。 You just have to source it to initialize the module command: 您只需要提供源代码即可初始化module命令:

source /app/modules/0/init/tcsh

As Armali says, the module command on tcsh is defined with the alias shell command. 正如Armali所说,tcsh上的模块命令是使用alias shell命令定义的。

With recent version of Modules (version 4+), you also have the possibility to define the module command in your current shell session with the autoinit subcommand of the modulecmd script: 使用最新版本的Modules(版本4+),您还可以使用modulecmd脚本的autoinit子命令在当前Shell会话中定义module命令:

eval `/app/modules/0/bin/modulecmd tcsh autoinit`

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

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