我现在正在研究TCL 脚本。当我运行tclsh script.tcl
脚本时完美运行,但是当我运行source script.tcl
命令时不再找到。
#!/usr/bin/env tclsh
proc test {} {
set a 43
set b 27
set c [expr $a + $b]
set d [expr [expr $a - $b]* $c]
for {set k 0} {$k < 10} {incr k} {
if {$k < 5} {
puts "k<5, pow=[expr pow($d,$k)]"
} else {
puts "k>=5, mod=[expr $d % $k]"
}
}
}
...运行时会导致错误:
$ source myfirst.tcl
Command 'proc, not found, did you mean:
command 'croc' from snap croc (6.4.10)
command 'prof' from deb profphd
command 'nproc' from deb coreutils
command 'proj' from deb proj-bin
See 'snap info <snapname>' for additional versions.
bash: myfirst.tcl: line 7: syntax error near undexpected token `k'