unknown.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:4k
- '"
- '" Copyright (c) 1993 The Regents of the University of California.
- '" Copyright (c) 1994-1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: unknown.n,v 1.4.12.1 2004/10/27 14:43:15 dkf Exp $
- '"
- .so man.macros
- .TH unknown n "" Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- unknown - Handle attempts to use non-existent commands
- .SH SYNOPSIS
- fBunknown fIcmdName fR?fIarg arg ...fR?
- .BE
- .SH DESCRIPTION
- .PP
- This command is invoked by the Tcl interpreter whenever a script
- tries to invoke a command that doesn't exist. The default implementation
- of fBunknownfR is a library procedure defined when Tcl initializes an
- interpreter. You can override the default fBunknownfR to change its
- functionality. Note that there is no default implementation of
- fBunknownfR in a safe interpreter.
- .PP
- If the Tcl interpreter encounters a command name for which there
- is not a defined command, then Tcl checks for the existence of
- a command named fBunknownfR.
- If there is no such command, then the interpreter returns an
- error.
- If the fBunknownfR command exists, then it is invoked with
- arguments consisting of the fully-substituted name and arguments
- for the original non-existent command.
- The fBunknownfR command typically does things like searching
- through library directories for a command procedure with the name
- fIcmdNamefR, or expanding abbreviated command names to full-length,
- or automatically executing unknown commands as sub-processes.
- In some cases (such as expanding abbreviations) fBunknownfR will
- change the original command slightly and then (re-)execute it.
- The result of the fBunknownfR command is used as the result for
- the original non-existent command.
- .PP
- The default implementation of fBunknownfR behaves as follows.
- It first calls the fBauto_loadfR library procedure to load the command.
- If this succeeds, then it executes the original command with its
- original arguments.
- If the auto-load fails then fBunknownfR calls fBauto_execokfR
- to see if there is an executable file by the name fIcmdfR.
- If so, it invokes the Tcl fBexecfR command
- with fIcmdfR and all the fIargsfR as arguments.
- If fIcmdfR can't be auto-executed, fBunknownfR checks to
- see if the command was invoked at top-level and outside of any
- script. If so, then fBunknownfR takes two additional steps.
- First, it sees if fIcmdfR has one of the following three forms:
- fB!!fR, fB!fIeventfR, or fB^fIoldfB^fInewfR?fB^fR?.
- If so, then fBunknownfR carries out history substitution
- in the same way that fBcshfR would for these constructs.
- Finally, fBunknownfR checks to see if fIcmdfR is
- a unique abbreviation for an existing Tcl command.
- If so, it expands the command name and executes the command with
- the original arguments.
- If none of the above efforts has been able to execute
- the command, fBunknownfR generates an error return.
- If the global variable fBauto_noloadfR is defined, then the auto-load
- step is skipped.
- If the global variable fBauto_noexecfR is defined then the
- auto-exec step is skipped.
- Under normal circumstances the return value from fBunknownfR
- is the return value from the command that was eventually
- executed.
- .SH EXAMPLE
- Arrange for the fBunknownfR command to have its standard behavior
- except for first logging the fact that a command was not found:
- .PP
- .CS
- # Save the original one so we can chain to it
- rename fBunknownfR _original_unknown
- # Provide our own implementation
- proc fBunknownfR args {
- puts stderr "WARNING: unknown command: $args"
- uplevel 1 [list _original_unknown {expand}$args]
- }
- .CE
- .SH "SEE ALSO"
- info(n), proc(n), interp(n), library(n)
- .SH KEYWORDS
- error, non-existent command