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