Hi to all and to you two that responded ...
The overall idea is that I want the aliases to work no matter what the user
shell is,
AND I don't want to have to be aware of the level of detail you'll read
about below
in order to create portable aliases. The 'addpath' example cannot be done
as
a separate script (environment variable inheritance is thankfully one way),
so
it must be an alias/function. Here is the code in the modulefiles I came up
with.
Example 1:
This is a simple alias with a parameter - no problem - works for any shell
because it's semantically simple enough.
set-alias ls {ls -F}
Examples 2:
This code makes an addpath alias and a 'col' alias.
The addpath alias is supposed to add something to your path, functionality I
want available to the person who loads the module;
and the col alias is supposed to return the nth word of each line of stdin.
if { [ module-info shelltype ] == "csh" } {
set-alias addpath { set path ( \$path $1 ) }
# the following is what happens when your code has to run
# through the tcl parser,
# then the csh to create the alias,
# and then the csh again whenever the alias is used
# start with this:
set-alias col [join { {awk '"'} "\{" {print "'\$''\\!\\!:1'"} "\}"
{'"} {'} } ""]
# set-alias runs this through the tcp interpreter, and inserts it
# between the single quotes in the string
# alias col ''
# which means that my expression must allow for these 'helpful'
# single quotes by assuming they'll be there. The result is
# alias col 'awk '"'{print "'$''\!\!:1'"}'"''
# which means that the runtime shell sees (when you type 'col n')
# awk '{print $!!:1}'
# which means, make awk show us the nth column of the stdin.
} else { # assume ksh, bash or sh
# there simply is a different syntax for doing this.
set-alias addpath { PATH=$PATH:$1 }
# Fro the col alias, sh type quoting is much easier to deal with,
but *different*, so I start with a different expression.
set-alias col { awk '\{ print $'$1' \}' }
# tcl interprets this down to the single word: awk '{ print $'$'1}'
# which is fed to the current shell in in an 'eval'
# with the result that the alias is defined as something that looks
the same but has word
# breaks where they need to be, and works when the user types 'col
n'
}
|