1unknown(n)                   Tcl Built-In Commands                  unknown(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       unknown - Handle attempts to use non-existent commands
9

SYNOPSIS

11       unknown cmdName ?arg arg ...?
12______________________________________________________________________________
13

DESCRIPTION

15       This  command is invoked by the Tcl interpreter whenever a script tries
16       to invoke a command that does not exist.  The default implementation of
17       unknown  is  a library procedure defined when Tcl initializes an inter‐
18       preter.  You can override the default unknown to change its functional‐
19       ity,  or you can register a new handler for individual namespaces using
20       the namespace unknown command.  Note that there is no default implemen‐
21       tation of unknown in a safe interpreter.
22
23       If the Tcl interpreter encounters a command name for which there is not
24       a defined command (in either  the  current  namespace,  or  the  global
25       namespace), then Tcl checks for the existence of an unknown handler for
26       the current namespace. By default, this  handler  is  a  command  named
27       ::unknown.   If  there is no such command, then the interpreter returns
28       an error.  If the unknown command exists (or a  new  handler  has  been
29       registered  for  the  current namespace), then it is invoked with argu‐
30       ments consisting of the fully-substituted name and  arguments  for  the
31       original  non-existent  command.   The  unknown  command typically does
32       things like searching through library directories for a command  proce‐
33       dure  with  the name cmdName, or expanding abbreviated command names to
34       full-length, or automatically executing unknown  commands  as  sub-pro‐
35       cesses.   In  some cases (such as expanding abbreviations) unknown will
36       change the original command slightly and  then  (re-)execute  it.   The
37       result  of  the  unknown command is used as the result for the original
38       non-existent command.
39
40       The default implementation of unknown behaves  as  follows.   It  first
41       calls  the  auto_load  library  procedure to load the command.  If this
42       succeeds, then it executes the original command with its original argu‐
43       ments.  If the auto-load fails then unknown calls auto_execok to see if
44       there is an executable file by the name cmd.  If so, it invokes the Tcl
45       exec  command with cmd and all the args as arguments.  If cmd cannot be
46       auto-executed, unknown checks to see if the command was invoked at top-
47       level  and  outside of any script.  If so, then unknown takes two addi‐
48       tional steps.  First, it sees if cmd has one  of  the  following  three
49       forms:  !!,  !event,  or  ^old^new?^?.  If so, then unknown carries out
50       history substitution in the same way that  csh  would  for  these  con‐
51       structs.   Finally,  unknown checks to see if cmd is a unique abbrevia‐
52       tion for an existing Tcl command.  If so, it expands the  command  name
53       and  executes  the command with the original arguments.  If none of the
54       above efforts has been able to execute the command,  unknown  generates
55       an  error  return.  If the global variable auto_noload is defined, then
56       the auto-load step is skipped.  If the global variable  auto_noexec  is
57       defined then the auto-exec step is skipped.  Under normal circumstances
58       the return value from unknown is the return value from the command that
59       was eventually executed.
60

EXAMPLE

62       Arrange  for  the  unknown command to have its standard behavior except
63       for first logging the fact that a command was not found:
64
65              # Save the original one so we can chain to it
66              rename unknown _original_unknown
67
68              # Provide our own implementation
69              proc unknown args {
70                  puts stderr "WARNING: unknown command: $args"
71                  uplevel 1 [list _original_unknown {*}$args]
72              }
73

SEE ALSO

75       info(n), proc(n), interp(n), library(n), namespace(n)
76

KEYWORDS

78       error, non-existent command, unknown
79
80
81
82Tcl                                                                 unknown(n)
Impressum