exit(n)

πŸ“¦
version 9.0.3 Β· 3 versions
, in alpine 3.23, alpine 3.24, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– 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 β€” code 1 is being reserved for "expected" error exits, so this trap uses 2 instead. 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