1unknown(n) Tcl Built-In Commands unknown(n)
2
3
4
5______________________________________________________________________________
6
8 unknown - Handle attempts to use non-existent commands
9
11 unknown cmdName ?arg arg ...?
12_________________________________________________________________
13
14
16 This command is invoked by the Tcl interpreter whenever a script tries
17 to invoke a command that doesn't exist. The default implementation of
18 unknown is a library procedure defined when Tcl initializes an inter‐
19 preter. You can override the default unknown to change its functional‐
20 ity. Note that there is no default implementation of unknown in a safe
21 interpreter.
22
23 If the Tcl interpreter encounters a command name for which there is not
24 a defined command, then Tcl checks for the existence of a command named
25 unknown. If there is no such command, then the interpreter returns an
26 error. If the unknown command exists, then it is invoked with argu‐
27 ments consisting of the fully-substituted name and arguments for the
28 original non-existent command. The unknown command typically does
29 things like searching through library directories for a command proce‐
30 dure with the name cmdName, or expanding abbreviated command names to
31 full-length, or automatically executing unknown commands as sub-pro‐
32 cesses. In some cases (such as expanding abbreviations) unknown will
33 change the original command slightly and then (re-)execute it. The
34 result of the unknown command is used as the result for the original
35 non-existent command.
36
37 The default implementation of unknown behaves as follows. It first
38 calls the auto_load library procedure to load the command. If this
39 succeeds, then it executes the original command with its original argu‐
40 ments. If the auto-load fails then unknown calls auto_execok to see if
41 there is an executable file by the name cmd. If so, it invokes the Tcl
42 exec command with cmd and all the args as arguments. If cmd can't be
43 auto-executed, unknown checks to see if the command was invoked at top-
44 level and outside of any script. If so, then unknown takes two addi‐
45 tional steps. First, it sees if cmd has one of the following three
46 forms: !!, !event, or ^old^new?^?. If so, then unknown carries out
47 history substitution in the same way that csh would for these con‐
48 structs. Finally, unknown checks to see if cmd is a unique abbrevia‐
49 tion for an existing Tcl command. If so, it expands the command name
50 and executes the command with the original arguments. If none of the
51 above efforts has been able to execute the command, unknown generates
52 an error return. If the global variable auto_noload is defined, then
53 the auto-load step is skipped. If the global variable auto_noexec is
54 defined then the auto-exec step is skipped. Under normal circumstances
55 the return value from unknown is the return value from the command that
56 was eventually executed.
57
59 Arrange for the unknown command to have its standard behavior except
60 for first logging the fact that a command was not found:
61
62 # Save the original one so we can chain to it
63 rename unknown _original_unknown
64
65 # Provide our own implementation
66 proc unknown args {
67 puts stderr "WARNING: unknown command: $args"
68 uplevel 1 [list _original_unknown {expand}$args]
69 }
70
71
73 info(n), proc(n), interp(n), library(n)
74
75
77 error, non-existent command
78
79
80
81Tcl unknown(n)