Version 1 of main script

Updated 2014-05-24 18:45:25 by RLE

The main script is the primary script that is executed by the interpreter, e.g. tclsh or wish.

Description

One common technique is to have a script run a self test if it detects that it is the main script. The detection routine usually looks something like this:

if {[info exists argv0] && $argv0 eq [info script]} {
    #do stuff
}

Examples of the following, more complicated test can be found:

#unneeded complexity ?
if {[info exists argv0] && [file tail [info script]] eq [file tail $argv0]} {
    #do stuff
}

but I (PYK) don't see a scenario in which is needed, as info script always has the same value as $argv0 in all the cases I tested.