Posted to tcl by patthoyts at Thu Aug 24 15:28:10 GMT 2006view pretty

If you want a command line program that runs under Windows using tclsh and not wish then the following code in a .bat or .cmd file ensures tclsh gets lauched and evaluates the contents:

::set HEADER { -*- tcl -*-
@echo off
echo %~0 %~f0
if "%OS%" == "Windows_NT" goto WinNT
tclsh "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto EOF
:WinNT
@rem this works for XP - probably not for 2k or NT
tclsh %~f0 %*
goto EOF
}
# --- cut here ---

foreach name [lsort [array names env]] {
   set spc [string repeat " " [expr {30 - [string length $name]}]]
   puts [concat $name $spc $env($name)]
}

puts "$argv0 $argv"
puts [info script]

# --- end ---
# \
:EOF