Reputation: 15084
I am programming in tcl (for use with the modules command). I need to find out what shell is being used by the user. Since I've never programmed in tcl before, I don't know what is wrong with my simple code. Can someone please advise?
set shell [module-info shell]
if { $shell=="bash" } {
puts "running bash"
}
The error I'm getting (sorry I didn't include it originally) is:
intel64(32):ERROR:102: Tcl command execution failed: if { $shell == "bash" } {
puts "running bash
}
Note that intel64 is the file where this code is found and line 34 is the last line.
Upvotes: 2
Views: 5985
Reputation: 1
set shell $::env(SHELL)
switch -glob $shell {
"/bin/tcsh" -
"/bin/csh" {
setenv foamDotFile $env(FOAM_INST_DIR)/OpenFOAM-2.3.0/etc/cshrc
}
"/bin/ksh" -
"/bin/bash" {
setenv foamDotFile $env(FOAM_INST_DIR)/OpenFOAM-2.3.0/etc/bashrc
}
}
Upvotes: 0
Reputation: 26547
The problem is that you should not use puts when using the modules software.
modules is just a tcl program that modifies somehow your shell environment in a shell-independent manner. This is done via a simple trick, check your environment:
set | grep -A 10 module
...
module ()
{
eval `/modules-3.2.9/Modules/$MODULE_VERSION/bin/modulecmd bash $*`
}
So the trick is creating a proper string that is then evaluated by the current shell. That string comes from stdout so what should have happened after it worked is that your shell should have complaint about trying to evaluate "running bash"
I'm puzzled as to why it's supposed to have worked after you added the missing quote.
Upvotes: 1
Reputation: 247162
Single quotes have no special meaning for Tcl. In Tcl, double quotes are analogous to shell double quotes, and braces ({}
) are analogous to shell single quotes. You would want to write
if { $shell == "bash" } ...
See the entire syntax of Tcl documented here: http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm
That doesn't explain the error message though. Tcl itself does not have a system
command. I can't say how this "modules command" extends Tcl. Try
puts "running bash"
or if you really really want to use echo
, then
exec echo running bash
Upvotes: 3
Reputation: 5375
2 comments:
Upvotes: 1