Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass arguments to set-alias in modulefile

I try to load a modulefile containing an alias from a bash shell. The tutorial page says the following about the set-alias command:

set-alias alias-name alias-string

Sets an alias or function with the name alias-name in the user's environment to the string alias-string. Arguments can be specified using the Bourne Shell style of function arguments. If the string contains "$1", then this will become the first argument when the alias is interpreted by the shell. The string "$*" corresponds to all of the arguments given to the alias. The character '$' may be escaped using the '\' character.

For some shells, aliases are not possible and the command has no effect. For Bourne shell derivatives, a shell function will be written (if supported) to give the impression of an alias. When a modulefile is unloaded, set-alias becomes unset-alias.

I want to use an alias to create a command that lets me start a given software with some specific parameters. Can anyone please point out what is wrong with the syntax below?

set-alias    cmd     "cmd $1 -cnf=/shared/$2 -ssh -etc"
like image 556
Tarjei Avatar asked Jan 03 '14 09:01

Tarjei


1 Answers

Because module scripts are written in Tcl, you need to quote Tcl metacharacters in the alias-string. The simplest way to do this is to put the alias in {braces} instead of "double-quotes".

set-alias cmd {cmd $1 -cnf=/shared/$2 -ssh -etc}
like image 146
Donal Fellows Avatar answered Oct 19 '22 04:10

Donal Fellows