LV example of some code to read through $PATH, looking for all the places a command might be found:
set cmd $::argv set sep ";" ; # For windows. set sep ":" ; # For unix. set dirlst [split $::env(PATH) ":"] foreach dir $dirlst { set tstfile [file join $dir $cmd] if {[file exists $tstfile]} { puts "$tstfile exists" } }I need to test the above to see if it works with files that contain special characters, like space.Yikes - there's a bug! The path I get on Windows (in MKS toolkit korn shell) has drive designators on each of the path designators and uses ";" instead of ":" as directory separators.
D. McC: This works for me to find an executable in $PATH on Linux:
proc inpath {prog} { set exok 0 # Original Linux version of "pathlist": set pathlist [split $::env(PATH) ":"] # Modified non-Linux version of "pathlist"--delete this line on Linux: set pathlist [split $::env(PATH) \ [expr {$::tcl_platform(platform) == "windows" ? ";" : ":"}]] foreach dir $pathlist { if {[file executable [file join $dir $prog]]} { set exok 1 break } } return $exok }# Examples:
% inpath supernotepad 1 % inpath bogomips 0LV MacOS or Windows may need to change that ":" to another character, depending on what their shell uses for PATH delimiters.MG On windows, it's always been a semi-colon. I've altered the example above to work on Windows, too (though, when looking for an exec, auto_execok works better). In the code above, you need to use inpath wish.exe, as opposed to auto_execok wish without the extension.