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

How can I source a shell script from Tcl?

1,525 views
Skip to first unread message

VashTheStampede

unread,
Sep 16, 2011, 1:25:33 PM9/16/11
to
I'm using Modules to configure the software environment on a cluster. It's written in Tcl. I need to source the Intel startup shell scripts to get all the compiler environment variables in place, but this seems challenging/impossible in Tcl. Is there any known work around?

I can't alter the shell scripts from intel.
I know it should be possible since I can append-path in the modulefile.

Thanks for your help!

Scott

Andreas Leitgeb

unread,
Sep 16, 2011, 1:46:00 PM9/16/11
to
VashTheStampede <scam...@gmail.com> wrote:
> I'm using Modules to configure the software environment on a cluster.
> It's written in Tcl. I need to source the Intel startup shell scripts
> to get all the compiler environment variables in place, but this seems
> challenging/impossible in Tcl. Is there any known work around?

I once had the problem of extracting the environment variables from
startup-scripts written for a different type of shell into my shell.

I ended up starting the shell that the scripts were written for, then
instructing that shell to dump its environment. This dumped environment
was then read into my shell, reformatted and filtered (throwing out
irrelevant vars), and sourced/eval'ed to define them as local variables.

In my case that were csh-scripts which I imported into bash, but the
principle would be the same for bash -> tcl, or even cmd.exe -> tcl

If you tell us, what interpreter the intel scripts are intended for,
and if they contain just variable-setting statements, or also some
non-trivial processing in that language, we can give more specific help.
Posting a representative excerpt of the intel-scripts might help, too.

> I know it should be possible since I can append-path in the modulefile.

I don't understand this line, though. What is "append-path"?

Alexandre Ferrieux

unread,
Sep 16, 2011, 2:00:00 PM9/16/11
to
On Sep 16, 7:25 pm, VashTheStampede <scami...@gmail.com> wrote:
> I'm using Modules to configure the software environment on a cluster. It's written in Tcl. I need to source the Intel startup shell scripts to get all the compiler environment variables in place, but this seems challenging/impossible in Tcl. Is there any known work around?
>
> I can't alter the shell scripts from intel.
> I know it should be possible since I can append-path in the modulefile.
>
> Thanks for your help!
>
> Scott

Just do things the other way: arrange for the unix shell scripts to
spawn the Tcl one. It will inherit all the env with no ugly parsing.
To do this, you might just write an "outer hull":

#! /bin/sh
. script1.sh
. script2.sh
exec tclsh ...

-Alex

scam...@gmail.com

unread,
Sep 20, 2011, 2:26:12 PM9/20/11
to a...@logic.at
First the easy question: append-path is a "module" specific command. Module is the (poorly named) environment management system we're using. The problem with importing the scripts is that each one, in turn sources some other scripts. (Also, there are sh and csh version of both.) Here's a csh example.

set PROD_DIR=/N/soft/mason/intel/composerxe-2011

if ( "$1" != "ia32" && "$1" != "intel64" && "$1" != "mic" ) then
echo "ERROR: Unknown switch '$1'. Accepted values: ia32, intel64, mic"
exit 1
endif



if ( -e $PROD_DIR/pkg_bin/idbvars.csh ) then
source $PROD_DIR/pkg_bin/idbvars.csh $1;
endif
if ( -e $PROD_DIR/tbb/bin/tbbvars.csh ) then
source $PROD_DIR/tbb/bin/tbbvars.csh $1;
endif
if ( -e $PROD_DIR/mkl/bin/mklvars.csh ) then
source $PROD_DIR/mkl/bin/mklvars.csh $1 $2;
endif
if ( -e $PROD_DIR/ipp/bin/ippvars.csh ) then
source $PROD_DIR/ipp/bin/ippvars.csh $1;
endif
if ( -e $PROD_DIR/pkg_bin/compilervars_arch.csh ) then
source $PROD_DIR/pkg_bin/compilervars_arch.csh $1;
endif

And for example mklvars.csh contains:

setenv MKLROOT /N/soft/mason/intel/composerxe-2011.2.137/mkl
setenv CPRO_PATH {$MKLROOT:s!/mkl!!}

setenv SCRIPT_NAME ${0}

setenv MOD_NAME mod

setenv MKL_TARGET_ARCH
setenv MKL_LP64_ILP64
setenv MKL_MOD
setenv MKL_VERBOSE

if ( "${1}" == "" ) then
goto Help
endif

while ( "$1" != "" )
if ( "$1" == "ia32" ) then
setenv MKL_TARGET_ARCH ia32
else if ( "$1" == "intel64" ) then
setenv MKL_TARGET_ARCH intel64
else if ( "$1" == "mic" ) then
setenv MKL_TARGET_ARCH intel64
else if ( "$1" == "lp64" ) then
setenv MKL_LP64_ILP64 lp64
else if ( "$1" == "ilp64" ) then
setenv MKL_LP64_ILP64 ilp64
else if ( "$1" == ${MOD_NAME} ) then
.
.
.
if ( "${MKL_VERBOSE}" == "verbose" ) then
echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
echo LIBRARY_PATH=${LIBRARY_PATH}
echo NLSPATH=${NLSPATH}
echo MANPATH=${MANPATH}
echo INCLUDE=${INCLUDE}
echo FPATH=${FPATH}
echo CPATH=${CPATH}
endif

goto End

Help:
echo ""
echo "Syntax:"
echo " $SCRIPT_NAME <arch> [MKL_interface] [${MOD_NAME}]"
echo ""
echo " <arch> must be is one of the following"
echo " ia32 : Set up for IA-32 target"
echo " intel64 : Set up for Intel(R) 64 target"
echo " mic : Set up for Intel(R) MIC target"
echo ""
echo " ${MOD_NAME} (optional) - set path to MKL F95 modules"
echo ""
echo " MKL_interface (optional) - MKL programming interface for intel64"
echo " Not applicable without ${MOD_NAME}"
echo " lp64 : 4 bytes integer (default)"
echo " ilp64 : 8 bytes integer"
echo ""
exit 1;

End:

I think I've determined that my only option is to re-write all of the shell scripts in tcl. Which is pretty awful...

Alexandre Ferrieux

unread,
Sep 20, 2011, 4:33:03 PM9/20/11
to
On Sep 20, 8:26 pm, scami...@gmail.com wrote:
>
> I think I've determined that my only option is to re-write all of the shell scripts in tcl. Which is pretty awful...

So you're ignoring the replies you got ?

-Alex

gavino

unread,
Sep 21, 2011, 12:08:14 AM9/21/11
to
just run the scrit from tcl
0 new messages