tclsh
Run Tcl scripts
SYNOPSIS
tclsh [options] [script-file [arg ...]]
PARAMETERS
script-file
The path to a Tcl script file to execute. If this argument is omitted, tclsh enters interactive mode, prompting for commands.
arg ...
Additional arguments passed to the Tcl script when executed. These arguments are accessible within the script via the global Tcl variables argv (a list of arguments) and argc (the count of arguments).
-encoding name
Specifies the character encoding used for reading the script-file. For example, -encoding utf-8 ensures the script is read using UTF-8 encoding.
-f
Forces interpretation of the first non-option argument as a script file, even if it begins with a hyphen (-), preventing it from being treated as another option.
-i
Forces tclsh to run in interactive mode, even if a script file is provided on the command line. This can be useful for debugging a script interactively after it has run.
-norc
Prevents the loading of the user's Tcl resource file (typically ~/.tclshrc.tcl or ~/.tclrc) upon startup. This is useful for clean, default environments.
-rcfile file
Specifies an alternative resource file to load instead of the default user resource file. The specified file must be a valid path to a Tcl script that will be sourced at startup.
-t
Equivalent to -i. Forces tclsh to run in interactive mode.
--
Marks the end of command-line options. All subsequent arguments are treated as the script file and its arguments, even if they begin with hyphens. This is useful for passing arguments that might otherwise be interpreted as options.
DESCRIPTION
tclsh is the standard interactive shell and script interpreter for the Tcl (Tool Command Language) scripting language. It provides a command-line interface where users can type Tcl commands and see the results immediately, or it can be used to execute Tcl scripts from a file. tclsh is primarily designed for console-based applications, system administration tasks, and scripting automation, lacking the graphical user interface capabilities found in its counterpart, wish (the Windowing Shell). It's a foundational component for developing Tcl-based applications and utilities, offering a robust environment for text processing, network scripting, and system interaction.
CAVEATS
tclsh provides a console-only environment. It does not support graphical user interface (GUI) elements or windowing toolkits directly. For Tcl applications requiring a GUI, the wish (Windowing Shell) interpreter, which includes the Tk toolkit, must be used instead. Additionally, while Tcl is highly portable, script behavior can sometimes differ subtly across various operating systems or Tcl versions.
MODES OF OPERATION
tclsh can operate in two primary modes:
1. Interactive Mode: When invoked without a script file (or with -i/-t), tclsh presents a prompt (typically %) where users can type Tcl commands directly. Each command is executed upon pressing Enter, and the result is displayed. This mode is excellent for testing commands, learning Tcl, and quick one-off tasks.
2. Script Mode: When invoked with a script file path, tclsh reads and executes the commands from the specified file. The shell typically exits after the script finishes execution, unless explicitly instructed to remain open or an error occurs. This mode is used for running full-fledged Tcl programs and automation scripts.
STANDARD I/O AND EXIT STATUS
tclsh interacts with the user and the system through standard input (stdin), standard output (stdout), and standard error (stderr). Commands like puts write to stdout, while error messages and debugging information are typically sent to stderr. In interactive mode, stdin is used to read user input. In script mode, stdin can be used by the script to read data, for example, via the gets command. Upon exiting, tclsh returns an exit status code to the operating system, indicating success (typically 0) or failure (non-zero).
HISTORY
Tcl was created by John Ousterhout while he was a professor at the University of California, Berkeley, and was first released in 1988. It was designed to be easily embedded into applications, providing a powerful scripting language for command and control. tclsh, as the core Tcl interpreter, has been a fundamental part of the Tcl distribution since its inception, serving as the primary way to interact with and execute Tcl scripts from the command line, enabling a wide range of system administration and automation tasks.