1 | '\" |
---|
2 | '\" Copyright (c) 1993 The Regents of the University of California. |
---|
3 | '\" Copyright (c) 1994-1996 Sun Microsystems, Inc. |
---|
4 | '\" |
---|
5 | '\" See the file "license.terms" for information on usage and redistribution |
---|
6 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
7 | '\" |
---|
8 | '\" RCS: @(#) $Id: unknown.n,v 1.9 2007/12/13 15:22:33 dgp Exp $ |
---|
9 | '\" |
---|
10 | .so man.macros |
---|
11 | .TH unknown n "" Tcl "Tcl Built-In Commands" |
---|
12 | .BS |
---|
13 | '\" Note: do not modify the .SH NAME line immediately below! |
---|
14 | .SH NAME |
---|
15 | unknown \- Handle attempts to use non-existent commands |
---|
16 | .SH SYNOPSIS |
---|
17 | \fBunknown \fIcmdName \fR?\fIarg arg ...\fR? |
---|
18 | .BE |
---|
19 | .SH DESCRIPTION |
---|
20 | .PP |
---|
21 | This command is invoked by the Tcl interpreter whenever a script |
---|
22 | tries to invoke a command that does not exist. The default implementation |
---|
23 | of \fBunknown\fR is a library procedure defined when Tcl initializes an |
---|
24 | interpreter. You can override the default \fBunknown\fR to change its |
---|
25 | functionality, or you can register a new handler for individual namespaces |
---|
26 | using the \fBnamespace unknown\fR command. Note that there is no default |
---|
27 | implementation of \fBunknown\fR in a safe interpreter. |
---|
28 | .PP |
---|
29 | If the Tcl interpreter encounters a command name for which there |
---|
30 | is not a defined command (in either the current namespace, or the |
---|
31 | global namespace), then Tcl checks for the existence of |
---|
32 | an unknown handler for the current namespace. By default, this |
---|
33 | handler is a command named \fB::unknown\fR. If there is no such |
---|
34 | command, then the interpreter returns an error. |
---|
35 | If the \fBunknown\fR command exists (or a new handler has been |
---|
36 | registered for the current namespace), then it is invoked with |
---|
37 | arguments consisting of the fully-substituted name and arguments |
---|
38 | for the original non-existent command. |
---|
39 | The \fBunknown\fR command typically does things like searching |
---|
40 | through library directories for a command procedure with the name |
---|
41 | \fIcmdName\fR, or expanding abbreviated command names to full-length, |
---|
42 | or automatically executing unknown commands as sub-processes. |
---|
43 | In some cases (such as expanding abbreviations) \fBunknown\fR will |
---|
44 | change the original command slightly and then (re-)execute it. |
---|
45 | The result of the \fBunknown\fR command is used as the result for |
---|
46 | the original non-existent command. |
---|
47 | .PP |
---|
48 | The default implementation of \fBunknown\fR behaves as follows. |
---|
49 | It first calls the \fBauto_load\fR library procedure to load the command. |
---|
50 | If this succeeds, then it executes the original command with its |
---|
51 | original arguments. |
---|
52 | If the auto-load fails then \fBunknown\fR calls \fBauto_execok\fR |
---|
53 | to see if there is an executable file by the name \fIcmd\fR. |
---|
54 | If so, it invokes the Tcl \fBexec\fR command |
---|
55 | with \fIcmd\fR and all the \fIargs\fR as arguments. |
---|
56 | If \fIcmd\fR cannot be auto-executed, \fBunknown\fR checks to |
---|
57 | see if the command was invoked at top-level and outside of any |
---|
58 | script. If so, then \fBunknown\fR takes two additional steps. |
---|
59 | First, it sees if \fIcmd\fR has one of the following three forms: |
---|
60 | \fB!!\fR, \fB!\fIevent\fR, or \fB^\fIold\fB^\fInew\fR?\fB^\fR?. |
---|
61 | If so, then \fBunknown\fR carries out history substitution |
---|
62 | in the same way that \fBcsh\fR would for these constructs. |
---|
63 | Finally, \fBunknown\fR checks to see if \fIcmd\fR is |
---|
64 | a unique abbreviation for an existing Tcl command. |
---|
65 | If so, it expands the command name and executes the command with |
---|
66 | the original arguments. |
---|
67 | If none of the above efforts has been able to execute |
---|
68 | the command, \fBunknown\fR generates an error return. |
---|
69 | If the global variable \fBauto_noload\fR is defined, then the auto-load |
---|
70 | step is skipped. |
---|
71 | If the global variable \fBauto_noexec\fR is defined then the |
---|
72 | auto-exec step is skipped. |
---|
73 | Under normal circumstances the return value from \fBunknown\fR |
---|
74 | is the return value from the command that was eventually |
---|
75 | executed. |
---|
76 | .SH EXAMPLE |
---|
77 | Arrange for the \fBunknown\fR command to have its standard behavior |
---|
78 | except for first logging the fact that a command was not found: |
---|
79 | .PP |
---|
80 | .CS |
---|
81 | # Save the original one so we can chain to it |
---|
82 | rename \fBunknown\fR _original_unknown |
---|
83 | |
---|
84 | # Provide our own implementation |
---|
85 | proc \fBunknown\fR args { |
---|
86 | puts stderr "WARNING: unknown command: $args" |
---|
87 | uplevel 1 [list _original_unknown {*}$args] |
---|
88 | } |
---|
89 | .CE |
---|
90 | .SH "SEE ALSO" |
---|
91 | info(n), proc(n), interp(n), library(n), namespace(n) |
---|
92 | .SH KEYWORDS |
---|
93 | error, non-existent command |
---|