Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Please HELP: Conversion of bashrc file to modulefile

318 views
Skip to first unread message

Sayan Bhakta

unread,
Feb 22, 2019, 12:12:32 AM2/22/19
to
Dear all,

I was trying to make a module file for a particular software- SPIDER.

The .bashrc file from which I was trying to make the module file is as below.

export SPIDER_DIR="/data/spider/spider2302/spider"
export SPBIN_DIR="$SPIDER_DIR/bin/"
export SPMAN_DIR="$SPIDER_DIR/man/"
export SPPROC_DIR="$SPIDER_DIR/proc/"
export PATH="${SPIDER_DIR}/bin:${PATH}"
export PATH="${SPIDER_DIR}/tools/bin:${PATH}"
export PATH="${SPIDER_DIR}/spire/spire_linux-1.5.5/bin:${PATH}"
export PUBSUB_DIR="$SPIDER_DIR/pubsub"
export PUBSUB_MASTER="sayan"


export JWEB_DIR="/data/spider/spider2302/web/jweb/linux"

export JAIHOME="$JWEB_DIR/j2re1.4.2_06/lib"
export JWEBCLASSPATH="$JWEB_DIR/linux.WEB.jar:$JAIHOME/mlibwrapper_jai.jar:$JAIHOME/jai_core.jar:$JAIHOME/jai_codec.jar"

if [ $?CLASSPATH ];then
export CLASSPATH="${JWEBCLASSPATH}:$CLASSPATH"
else
export CLASSPATH="$JWEBCLASSPATH"
fi

alias jweb='$JWEB_DIR/j2re1.4.2_06/bin/java -Xmx512m -Djava.util.prefs.syncInterval=2000000 web/StartWeb'

export SPRGB_DIR="/data/spider/spider2302/web/bin"
alias web='$SPRGB_DIR/web_linux_tru'


When sourcing the .bashrc file, all the environment variables are set properly and I can run the software without any error.

My modulefile goes as below.


#%Module1.0#####################################################################
##
## modules modulefile
##
## modulefiles/spider2302. Written by Sayan Bhakta
##
proc ModulesHelp { } {
global version prefix

puts stderr "\tspider2302 - loads all the environment and softwares for SPIDER2302\n"
}

module-whatis "loads all the environment and softwares for SPIDER2302"



# for Tcl script use only


#SPIDER2302

set SPIDER_DIR /data/spider/spider2302/spider
setenv SPIDER_DIR $SPIDER_DIR/
prepend-path SPBIN_DIR $SPIDER_DIR/bin/
prepend-path SPMAN_DIR $SPIDER_DIR/man/
prepend-path SPPROC_DIR $SPIDER_DIR/proc/
prepend-path PATH $SPIDER_DIR/bin/:$SPIDER_DIR/tools/bin/:$SPIDER_DIR/spire/spire_linux-1.5.5/bin/
#prepend-path PATH $SPIDER_DIR/tools/bin
#prepend-path PATH $SPIDER_DIR/spire/spire_linux-1.5.5/bin
prepend-path PUBSUB_DIR $SPIDER_DIR/pubsub
prepend-path PUBSUB_MASTER sayan
set-alias spider spider_linux_mp_intel64

#JWEB

set JWEB_DIR /data/spider/spider2302/web/jweb/linux
setenv JAIHOME $JWEB_DIR/j2re1.4.2_06/lib/
set JAIHOME $JWEB_DIR/j2re1.4.2_06/lib/
prepend-path JWEBCLASSPATH $JWEB_DIR/linux.WEB.jar:$JAIHOME/mlibwrapper_jai.jar:$JAIHOME/jai_core.jar:$JAIHOME/jai_codec.jar
#prepend-path CLASSPATH $JAIHOME/mlibwrapper_jai.jar:$JAIHOME/jai_core.jar:$JAIHOME/jai_codec.jar
#setenv JAIBIN $JWEB_DIR/j2re1.4.2_06/bin/
#set-alias jweb java -Xmx512m -Djava.util.prefs.syncInterval=2000000 web/StartWeb

#set JWEBCLASSPATH $JWEB_DIR/linux.WEB.jar
#set CLASSPATH $JWEBCLASSPATH

if { $CLASSPATH } {
setenv CLASSPATH $JWEBCLASSPATH:$CLASSPATH
} else {
setenv CLASSPATH $JWEBCLASSPATH
}

set-alias jweb $JWEB_DIR/j2re1.4.2_06/bin/java web/StartWeb -Xmx512m -Djava.util.prefs.syncInterval=2000000 web/StartWeb

#WEB
set WEB_DIR /data/spider/spider2302/web
setenv SPRGB_DIR $WEB_DIR/bin
set-alias web $WEB_DIR/bin/web_linux_tru

#module use


When trying to load the modulefile, the error shown is as given below.

spider2302(51):ERROR:102: Tcl command execution failed: if { $CLASSPATH } {
setenv CLASSPATH $JWEBCLASSPATH:$CLASSPATH
} else {
setenv CLASSPATH $JWEBCLASSPATH
}


Please help.

Andreas Leitgeb

unread,
Feb 22, 2019, 3:03:34 AM2/22/19
to
Sayan Bhakta <19sayan...@gmail.com> wrote:
> When trying to load the modulefile, the error shown is as given below.
> spider2302(51):ERROR:102: Tcl command execution failed: if { $CLASSPATH } {
> setenv CLASSPATH $JWEBCLASSPATH:$CLASSPATH
> } else {
> setenv CLASSPATH $JWEBCLASSPATH
> }

Tcl's "if" wants a boolean value to determine execution flow.
Most likely, $CLASSPATH is a (potentially empty) string, so
the first line probably should rather be:
if { $CLASSPATH ne "" } {

I can only assume that command "setenv" has been defined
somewhere else, because Tcl itself doesn't have such a command.

Sayan Bhakta

unread,
Feb 22, 2019, 1:06:05 PM2/22/19
to
> Tcl's "if" wants a boolean value to determine execution flow.
> Most likely, $CLASSPATH is a (potentially empty) string, so
> the first line probably should rather be:
> if { $CLASSPATH ne "" } {
>
> I can only assume that command "setenv" has been defined
> somewhere else, because Tcl itself doesn't have such a command.

Thank you for your reply. However it's not working.

When I am giving

if { $CLASSPATH ne "" } {

It shows the same error.

PS. I am trying to create a module file. I think the setenv is already defined in the module package!!

Rich

unread,
Feb 22, 2019, 1:14:12 PM2/22/19
to
Sayan Bhakta <19sayan...@gmail.com> wrote:
>> Tcl's "if" wants a boolean value to determine execution flow.
>> Most likely, $CLASSPATH is a (potentially empty) string, so
>> the first line probably should rather be:
>> if { $CLASSPATH ne "" } {
>>
>> I can only assume that command "setenv" has been defined
>> somewhere else, because Tcl itself doesn't have such a command.
>
> Thank you for your reply. However it's not working.
>
> When I am giving
>
> if { $CLASSPATH ne "" } {
>
> It shows the same error.

The error you quoted in your OP was "command execution failed" - which
implies that "setenv" is not defined (because "command execution
failed" implies Tcl was trying to execute a command). There is no
"setenv" nor "prepend-path" commands in base Tcl, so unless they are
defined somewhere else, your script is incorrect on its face (to the
extent we've seen what you've posted).

> PS. I am trying to create a module file. I think the setenv is
> already defined in the module package!!

Next question: why?

You'll be unable to run your Tcl script to set bash environment
variables in your bash environment (a Unix process can not effect its
parents environment variable settings, only its own). So you can't
replace sourcing a bash setup file with running a Tcl module. Basic
Unix process separation prevents that from working.



Sayan Bhakta

unread,
Feb 22, 2019, 1:25:14 PM2/22/19
to
I have already been successful in replacing a .bashrc file with a module file.

And I am not the innovator. There are multiple evidences of modulefiles which I can load in the bash environment. That's how the "ENVIRONMENT MODULES" works I think.

http://modules.sourceforge.net/man/modulefile.html


It's not the setenv command that is inhibiting me to successfully run the script. Because before the line the error is referring to there are multiple lines where setenv command is given and it's reading it successfully I suppose.

I might be doing something wrong in the "if" condition and in the "set-alias" command.....

Please help me resolve these issues in those lines.

Rolf Ade

unread,
Feb 22, 2019, 2:30:10 PM2/22/19
to

Sayan Bhakta <19sayan...@gmail.com> writes:
> On Friday, February 22, 2019 at 11:44:12 PM UTC+5:30, Rich wrote:
>> Sayan Bhakta <19sayan...@gmail.com> wrote:
>> >> Tcl's "if" wants a boolean value to determine execution flow.
>> >> Most likely, $CLASSPATH is a (potentially empty) string, so
>> >> the first line probably should rather be:
>> >> if { $CLASSPATH ne "" } {
>> >>
>
> I might be doing something wrong in the "if" condition and in the "set-alias" command.....
>
> Please help me resolve these issues in those lines.

While Rich is right that you often enouth can't have just

if {$CLASSPATH} {...}

- you can only if the value of CLASSPATH is a boolean - the problem may
be, that the variable CLASSPATH isn't set at all.

At least in the code you showed in your initial post, every action that
may set CLASSPATH was commented out:

#prepend-path CLASSPATH $JAIHOME/mlibwrapper_jai.jar:$JAIHOME/jai_core.jar:$JAIHOME
[...]
#set CLASSPATH $JWEBCLASSPATH

If that is your problem then one would expect another error msg that the
one you presented but this is maybe you not using a plain tclsh (but
something enhanced for your task).


Rich

unread,
Feb 22, 2019, 6:00:07 PM2/22/19
to
Sayan Bhakta <19sayan...@gmail.com> wrote:
> And I am not the innovator. There are multiple evidences of
> modulefiles which I can load in the bash environment. That's how the
> "ENVIRONMENT MODULES" works I think.
>
> http://modules.sourceforge.net/man/modulefile.html

Three postings from you before you reveal to us a critical fact. That
fact being that you are using a custom system for this.

Don't you think that this factoid might have been even slightly
important to have revealed, *up front*, when posting questions on a
general Tcl newsgroup?

> I might be doing something wrong in the "if" condition and in the
> "set-alias" command.....

Assuming that the snippets you've posted (well, at least the second
one) the overall syntax looks ok (at least from a Tcl syntax
perspective).

> Please help me resolve these issues in those lines.

Assuming you actually made the edits, and that you were actually
sourcing the edited file, nothing sticks out as being a Tcl syntax
error (at least from the Tcl level). So this likely means some trouble
from the 'modules' system, and for help with that you'll have to ask
the folks that support the 'modules' system.

Andreas Leitgeb

unread,
Feb 23, 2019, 11:22:03 AM2/23/19
to
Sayan Bhakta <19sayan...@gmail.com> wrote:
> On Friday, February 22, 2019 at 11:44:12 PM UTC+5:30, Rich wrote:
>> Sayan Bhakta <19sayan...@gmail.com> wrote:
>> >> Tcl's "if" wants a boolean value to determine execution flow.
>> >> Most likely, $CLASSPATH is a (potentially empty) string, so
>> >> the first line probably should rather be:
>> >> if { $CLASSPATH ne "" } {
>> > Thank you for your reply. However it's not working.
>> > When I am giving
>> > if { $CLASSPATH ne "" } {
>> > It shows the same error.

There are still two possibilities I see (either or both might be the
problem)

1.) in tclsh, environment variables are fields of the "env" array,
so maybe you need to check for $env(CLASSPATH) rather than for
$CLASSPATH . But it is also possible that this "modules"-thingie
auto-maps the environment into local variables, anyway, if existing.

2.) if the variable $CLASSPATH doesn't exist, then in tclsh unlike
bash&co you cannot just dereference it with a dollar.

Either you first check for it's existence explicitly:

if {[info exists CLASSPATH] && $CLASSPATH ne ""} {

or you write a helper proc like this:

proc isVarSet {varname} {
upvar 1 $varname var; expr {[info exists var] && $var ne ""}
}
and then make the discussed line so:
if {[isVarSet CLASSPATH]} {


In case 1.) and 2.) both apply, make it:

if {[info exists env(CLASSPATH)] && $env(CLASSPATH) ne ""} {

or together with that helper proc isVarSet (unchanged - don't add
any "env" inside it, only to its call):

if {[isVarSet env(CLASSPATH)]} {


0 new messages