tclsh(1)
Okay bestie, manual page for tclsh(1) is here and it's giving tiny shell with a whole Tcl brain π§π
π NAME π
tclsh - Simple shell containing Tcl interpreter β¨
πΈ SYNOPSIS πΈ
tclsh ?-encoding name? ?fileName arg arg ...?
π DESCRIPTION π
okay so tclsh is a shell-like app that reads Tcl commands from standard input or from a file, then evaluates them π¦ With no arguments it runs interactively, reading commands from standard input and printing results and error messages to standard output. It keeps going until you invoke the exit command or it hits end-of-file on standard input π
Also, if there's a file called .tclshrc (or tclshrc.tcl on Windows) in your home directory, interactive tclsh will evaluate it as a Tcl script right before it reads the first command from standard input. Main character setup, no cap π
π¦ SCRIPT FILES π¦
If you invoke tclsh with arguments, the first few arguments name a script file and, optionally, the encoding of the text data stored in that script file. Any extra arguments get handed to the script as variables (see below) β¨ Instead of reading standard input, tclsh reads Tcl commands from that named file, and it exits when it reaches the end of the file π
The end of the file can be marked either by the physical end of the medium, or by the character "\032" ("\u001a", control-Z). If that character shows up in the file, the tclsh app reads text up to but not including it. Need that character in your file? Encode it safely as "\032", "\x1A", or "\u001a", or generate it with commands like format or binary. It's giving careful π«Ά
There is no automatic evaluation of.tclshrcwhen you pass a script file on thetclshcommand line. Your script can alwayssourceit manually if you want it, though π
If you make a Tcl script whose first line is:
#!/usr/local/bin/tclsh
then you can run the script file directly from your shell, as long as you mark the file as executable π₯ This assumes tclsh got installed in the default location, /usr/local/bin. If it's somewhere else, you'll have to edit that line to match π Many UNIX systems won't let the #! line go over about 30 characters, so make sure the tclsh executable can be reached with a short file name π
An even better approach? Start your script files with these three lines:
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" ${1+"$@"}
This approach has three advantages over the one above π First, the location of the tclsh binary doesn't have to be hard-wired into the script. It can live anywhere on your shell search path β¨ Second, it gets around the 30-character file name limit. Third, it works even if tclsh is itself a shell script (some systems do this to handle multiple architectures or operating systems, where the tclsh script picks one of several binaries to run) π§
Here's how the three lines work: both sh and tclsh process the script, but the exec only gets executed by sh. sh processes the script first, treats the second line as a comment, and executes the third line. The exec statement makes the shell stop processing and start up tclsh to reprocess the entire script. When tclsh starts up, it treats all three lines as comments, since the backslash at the end of the second line makes the third line part of the comment on the second line π
Also, it's super common to install tclsh with its version number in the name π This lets multiple Tcl versions live on the same system at once, but it makes it harder to write scripts that start up uniformly across different Tcl versions. Tradeoffs, bestie π₯Ί
π VARIABLES π
tclsh sets the following global Tcl variables, in addition to the ones the Tcl library creates itself (like env, which maps environment variables such as PATH into Tcl) π
argcβ Contains a count of the number ofargarguments (0 if none), not including the name of the script file.argvβ Contains a Tcl list whose elements are theargarguments, in order, or an empty string if there are noargarguments.argv0β ContainsfileNameif it was specified. Otherwise, it contains the name by whichtclshwas invoked.tcl_interactiveβ Contains1iftclshis running interactively (nofileNamewas specified and standard input is a terminal-like device),0otherwise.
π¬ PROMPTS π¬
When tclsh runs interactively, it normally prompts for each command with "% " π You can change the prompt by setting the global variables tcl_prompt1 and tcl_prompt2. If tcl_prompt1 exists, it must be a Tcl script that outputs a prompt. Instead of outputting a prompt directly, tclsh evaluates the script in tcl_prompt1 β¨ The variable tcl_prompt2 works similarly when you hit newline but the current command isn't complete yet. If tcl_prompt2 isn't set, then no prompt gets output for incomplete commands π¦
π STANDARD CHANNELS π
See Tcl_StandardChannels for more explanations π§
π SEE ALSO π
auto_path(3tcl), encoding(3tcl), env(3tcl), fconfigure(3tcl) π
π«§ KEYWORDS π«§
application, argument, interpreter, prompt, script file, shell π
That's the whole tea, bestie ππ Tcl source, tclsh(1) page, all sealed with a π and a π«Ά
π¦ where this page comes from
- debian bookworm: tcl8.6 8.6.13+dfsg-2
- debian trixie: tcl8.6 8.6.16+dfsg-1
- ubuntu jammy: tcl8.6 8.6.12+dfsg-1build1
- ubuntu noble: tcl8.6 8.6.14+dfsg-1build1
- ubuntu questing: tcl8.6 8.6.17+dfsg-1
- ubuntu resolute: tcl8.6 8.6.17+dfsg-1build1
- ubuntu stonking: tcl8.6 8.6.18+dfsg-1
- Copyright (c) 1993 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms