Building network automation solutions

9 module online course

Start now!

Tclsh command line parameters

In a previous post, I’ve described how to execute a Tcl file with the tclsh command.

You can do even more than that: you can pass parameters to the executed file. Every word you enter after the file name in the tclsh command line is passed as a parameter to the Tcl code you execute. To get these parameters in Tcl, use Tcl commands similar to the code below:

# loop.tcl: changes loopback state
# syntax: tclsh loop.tcl ifnum state
set ifnum [lindex $argv 0] # first parameter after file name
set ifstate [lindex $argv 1] # second parameter after file name
if {[string equal $ifstate ""]} {
return -code error "Syntax: loop.tcl ifnum ifstate"
... rest of procedure ...
Add comment