Version 3 of tclsh application template

Updated 2003-01-28 16:58:30

This template code is for starting a typical tclsh application.

 #! /bin/sh
 # the next line restarts using tclsh \
 exec tclsh "$0" ${1+"$@"}

This is a little more sophisticated than the code suggested on the tclsh man page (see tcl), and is explained in great detail on exec magic.

Typical patterns to continue are:

  • verify Tcl version requirements
 package require Tcl 8.4    ;# My application uses [lset]
  • process stdin:
 while {[gets stdin line]>=0} {
   #do something with $line
 }
  • process argv:
 foreach arg $argv {
   # do something with $arg
 }

Category Example