1

I have problem with refactoring bash command into tcsh-friendly command. Don't know the tcsh syntax very well so the error im receiving doens't give me any clue.

The whole bash script was about adding modules on server

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

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?

Elcardia
  • 135
  • 10
  • 1
    tcsh doesn't have functions at all. From what I recall, you'd have to write an alias instead. I question whether this is worth the effort. – chepner Apr 04 '19 at 13:58

2 Answers2

1

chepner is right saying tcsh doesn't have functions at all and you'd have to write an alias instead. 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 \!*.

Armali
  • 18,255
  • 14
  • 57
  • 171
0

The module command you want to port from bash to tcsh already comes with an initialization file to the 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.

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. You just have to source it to initialize the module command:

source /app/modules/0/init/tcsh

As Armali says, the module command on tcsh is defined with the alias shell command.

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:

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