Bobby
Bobby

Reputation: 37

when I run my TCL script is there a way I can add a command or a variable with my run command?

What I am trying to do is run my TCL script with a variable.

So for example lets say my script was called example.tcl.

I want to be able to run that script doing something like this:

tclsh example.tcl success 

Then in my tcl script I will have:

set status = variable  <---- this variable should be equal to "success"
puts $status 

Is there anyway in TCL I can do something like that?

Upvotes: 0

Views: 110

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137557

The arguments to tclsh after the script name are stored as a list in the global argv variable.

set status [lindex $argv 0]
puts "status = $status"

The length of the list is in argc, but nobody really uses that. The script is in argv0, not in argv; that's very convenient sometimes.

Upvotes: 2

Related Questions