使用tclsh时如何将参数传递给tcl脚本

时间:2015-10-24 06:48:19

标签: tcl tclsh

我有两个要传递参数的tcl脚本。第一个得到一个数字并给出它的阶乘,第二个得到两个数字并执行一些条件和相应的输出。我在Cygwin上使用tclsh。当我以这种方式运行脚本时,我无法将参数传递给脚本:
List<Object> objects = new ArrayList<Object>(); objects.add(selectContactCBox); objects.add(addContactBtn); objects.add(personalRadio); objects.add(businessRadio); for(object o: objects){ o.addActionListener(this); }
这给出了错误,我没有为脚本提供适当数量的参数 为了传递参数,我尝试了以下内容,但最终收到错误“close-brace之后的额外字符”:
$ tclsh fact.tcl
factorial的tcl代码是:

tclsh fact.tcl 5

条件的tcl代码(第二个脚本)如下:

if {$argc !=1} {
    puts stderr "Error! ns called with wrong number of arguments! ($argc)"
    exit 1
} else {
    set f [lindex $argv 0]
}


proc Factorial {x} {
for {set result 1} {$x>1}{set x [expr $x - 1]}{
    set result [expr $result * $x]
}
return $result
}
set res [Factorial $f]
puts "Factorial of $f is $res"

0 个答案:

没有答案
相关问题