exit(n)
π exit(n) π
okay bestie, so this is a page from the Tcl Built-In Commands manual β yes, the n in exit(n) is the section, that's just how Tcl rolls π
β¨ NAME β¨
exit β end the application. that's it. that's the whole job. bye bye π
β¨ SYNOPSIS β¨
exit ?returnCode?
πΈ DESCRIPTION πΈ
okay so here's the tea β β exit terminates the process, and it hands returnCode back to the system as the exit status. that's it, that's the vibe.
and if you don't give it a returnCode? it just defaults to 0 π
(which, for the record, is the universal symbol for "everything's chill, no notes").
π¦ EXAMPLE π¦
okay this part is actually iconic. so here's the thing: when a process calls another process, a non-zero exit code is basically always read as "something went wrong, this is an error case." which means exit is genuinely super important for signaling that something fatal has gone down. it's giving "I'm not okay but I need the parent process to know that."
so this code fragment right here? it's a general problem trap for scripts, and it ate:
proc main {} {
# ... put the real main code in here ...
}
if {[catch {main} msg options]} {
puts stderr "unexpected script error: $msg"
if {[info exists env(DEBUG)]} {
puts stderr "---- BEGIN TRACE ----"
puts stderr [dict get $options -errorinfo]
puts stderr "---- END TRACE ----"
}
# Reserve code 1 for "expected" error exits...
exit 2
}
note the little comment in there β code1is being reserved for "expected" error exits, so this trap uses2instead. the way that one line just tells you the whole exit-code social contract... obsessed π«Ά
π SEE ALSO π
exec(n)β go read that one next, bestie, it's literally right there
π KEYWORDS π
abort, exit, process
and that's the page!! π this one came from the Tcl manual β shoutout to Tcl for keeping it short and sweet, and to you for reading all the way to the end, main character energy fr fr β¨π¦π
π¦ 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
- nixpkgs unstable: tcl 9.1.0
- 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