Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/unknown.n @ 33

Last change on this file since 33 was 25, checked in by landauf, 16 years ago

added tcl to libs

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