Version 2 of main script

Updated 2014-05-24 18:56:33 by pooryorick

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
}

or , as formulated in a comp.lang.tcl posting by DKF:

if {[string equal $::argv0 [info script]] || [
    array exists ::embed_args]} {
    main
} 

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 .