I am new to tcl
I wrote a code as ...
#!/usr/bin/tclsh
# get all co-ordinates of cell from arguments
# if suffiecient arguments are not there then print error and exit
# Calculate area of cell
lassign $argv a b c d e f g h
if {$argc != 8} {
puts "Error in argument count"
exit
} elseif {$b > $d} {
puts "Error: x1 is greater than x2 value"
exit
} elseif {$f > $h} {
puts "Error: y1 value is greater than y2"
exit
}
puts "Everything is correct proceed"
set area [expr ($d - $b) * ($h - $f)]
puts "Area of cell is $area"
when executing in mac terminal as...
source ./special_var.txt x1 20 x2 30 y1 30 y2 60
i am getting error as ...
wrong # args: should be "source ?-encoding name? fileName"
                        
You've written a file that's trying to be a program (it has a
#!line and depends on theargvglobal variable). That's fine, but you should run it withtclsh(explicitly or implicitly); you can't do it simply withsource, which is a more primitive operation.Running it as a subprocess is pretty easy:
or, if you have marked the file as executable in the OS:
Running in the current process is slightly trickier. The
sourcecommand is more like#includein C; it doesn't do much special processing of arguments by itself, and if you want that then you have to do that first. It's not a lot of code...We've never added that to
source(and aren't going to!) because we don't usually want to interfere withargvjust because we pull code from another file.