O'Reilly logo

Practical Programming in Tcl & Tk, Third Edition by Brent B. Welch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

UNIX Tcl Scripts

On UNIX you can create a stand alone Tcl or Tcl/Tk script much like an sh or csh script. The trick is in the first line of the file that contains your script. If the first line of a file begins with #!pathname, then UNIX uses pathname as the interpreter for the rest of the script. The “Hello, World!” program from Chapter 1 is repeated in Example 2-1 with the special starting line:

Example 2-1 A standalone Tcl script on UNIX.
#!/usr/local/bin/tclsh
puts stdout {Hello, World!}

Similarly, the Tk hello world program from Chapter 21 is shown in Example 2-2:

Example 2-2 A standalone Tk script on UNIX.
#!/usr/local/bin/wish
button .hello -text Hello -command {puts "Hello, World!"}
pack .hello -padx 10 -pady 10

The actual pathnames ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required