Version 5 of main script

Updated 2014-05-24 20:08: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 following more complete detection method is required for correct behaviour when pkg_mkIndex is being used:

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

Another variation :

if {![info exists argv0] || [
  file tail [info script]] ne [file tail $argv0]} return

# test/standalone code follows

The more simple and naive approach to detection method only compares info script with $argv0 :

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
} 

authors

dfk
cjl
PYK
   [RS] :