unknown(n)
π unknown(n) β Tcl Built-In Commands
okay bestie, pull up a chair πͺ because this one is literally the "who dis??" of the Tcl world and honestly it's giving main character energy.
β¨ NAME β¨
unknown β the lil handler that catches you when you try to run a command that does not exist π«
π SYNOPSIS π
unknown cmdName ?arg arg ...?
πΈ DESCRIPTION πΈ
so here's the tea π β this command gets invoked by the Tcl interpreter whenever a script tries to invoke a command that does not exist. the default implementation of unknown is a library procedure that gets defined when Tcl initializes an interpreter. you can override the default unknown to change what it does, or you can register a whole new handler for individual namespaces using the namespace unknown command. note: there is no default implementation of unknown in a safe interpreter. π
if the Tcl interpreter runs into a command name that has no defined command (like, neither in the current namespace nor the global namespace), then Tcl checks whether there's an unknown handler for the current namespace. by default that handler is a command named ::unknown. if there's no such command, the interpreter just returns an error. π
if the unknown command does exist (or a new handler has been registered for the current namespace), then it gets invoked with arguments consisting of the fully-substituted name and arguments for the original non-existent command. the unknown command typically does stuff like searching through library directories for a command procedure with the name cmdName, or expanding abbreviated command names to full-length, or automatically executing unknown commands as sub-processes. in some cases (like when it's expanding abbreviations) unknown will change the original command slightly and then (re-)execute it. and the result of the unknown command is used as the result for the original non-existent command. slay, honestly. β¨
π¦ the default behavior, explained π¦
the default implementation of unknown behaves like this, okay:
- it first calls the
auto_loadlibrary procedure to load the command. if that succeeds, it executes the original command with its original arguments. π«Ά - if the auto-load fails and Tcl is running interactively, then
unknowncallsauto_execokto see if there's an executable file by the name cmd. if so, it invokes the Tclexeccommand with cmd and all the args as arguments. π₯ - if cmd can't be auto-executed,
unknownchecks whether the command was invoked at top-level and outside of any script. if so,unknowntakes two additional steps:- first, it sees if cmd has one of the following three forms:
!!,!event, or^old^new?^?. if so, thenunknowncarries out history substitution in the same way thatcshwould for these constructs. π - finally,
unknownchecks whether cmd is a unique abbreviation for an existing Tcl command. if so, it expands the command name and executes the command with the original arguments. β
- first, it sees if cmd has one of the following three forms:
- if none of the above efforts has been able to execute the command,
unknowngenerates an error return. π
also, heads up:
- if the global variable
auto_noloadis defined, then the auto-load step is skipped. - if the global variable
auto_noexecis defined then the auto-exec step is skipped.
under normal circumstances the return value from unknown is the return value from the command that was eventually executed. periodt. π
π EXAMPLE π
arrange for the unknown command to have its standard behavior, except first it logs the fact that a command was not found:
# Save the original one so we can chain to it
rename unknown _original_unknown
# Provide our own implementation
proc unknown args {
puts stderr "WARNING: unknown command: $args"
uplevel 1 [list _original_unknown {*}$args]
}
not us writing a whole wrapper so we can gossip about every typo π iconic.
π SEE ALSO π
info(n), proc(n), interp(n), library(n), namespace(n)
π KEYWORDS π
error, non-existent command, unknown
fr fr bestie, remember: unknown is your safety net, not your vibe-ruiner. it catches the command that never was and gives it a whole second chance. π§
this has been unknown(n) from the Tcl Built-In Commands manual β Tcl, unknown(n). mwah, go forth and handle your non-existent commands, queen ππ
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- Copyright (c) 1993 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms