Tcl: How to determine whether command exists in PATH?

From FVue
Jump to: navigation, search


How can I - from within tcl - determine whether a command exists anywhere in my $PATH? In bash I can do type -P. I understand the behavior of which(1) is not reliable across platforms[1].


The Tcl library provides an auto_execok command:

auto_execok cmd
Determines whether there is an executable file by the name cmd. This command examines the directories in the current search path (given by the PATH enviornment variable) to see if there is an executable file named cmd in any of those directories. If so, it returns 1; if not it returns 0. Auto_exec remembers information about previous searches in an array named auto_execs; this avoids the path search in future calls for the same cmd. The command auto_reset may be used to force auto_execok to forget its cached information.


blog comments powered by Disqus