{
    "mode": "man",
    "parameter": "tclsh",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/tclsh/1/json",
    "generated": "2026-05-30T07:09:45Z",
    "synopsis": "tclsh ?-encoding name? ?fileName arg arg ...?",
    "sections": {
        "NAME": {
            "content": "tclsh - Simple shell containing Tcl interpreter\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "tclsh ?-encoding name? ?fileName arg arg ...?\n\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Tclsh  is  a shell-like application that reads Tcl commands from its standard input or from a\nfile and evaluates them.  If invoked with no arguments then it  runs  interactively,  reading\nTcl  commands from standard input and printing command results and error messages to standard\noutput.  It runs until the exit command is invoked or until it  reaches  end-of-file  on  its\nstandard input.  If there exists a file .tclshrc (or tclshrc.tcl on the Windows platforms) in\nthe home directory of the user, interactive tclsh evaluates the file as a Tcl script just be‐\nfore reading the first command from standard input.\n",
            "subsections": []
        },
        "SCRIPT FILES": {
            "content": "If  tclsh is invoked with arguments then the first few arguments specify the name of a script\nfile, and, optionally, the encoding of the text data stored in that script  file.  Any  addi‐\ntional arguments are made available to the script as variables (see below).  Instead of read‐\ning commands from standard input tclsh will read Tcl commands from  the  named  file;   tclsh\nwill  exit  when it reaches the end of the file.  The end of the file may be marked either by\nthe physical end of the medium, or by the character, “\\032” (“\\u001a”, control-Z).   If  this\ncharacter  is present in the file, the tclsh application will read text up to but not includ‐\ning the character.  An application that requires this character in the file may safely encode\nit  as  “\\032”,  “\\x1A”, or “\\u001a”; or may generate it by use of commands such as format or\nbinary.  There is no automatic evaluation of .tclshrc when the name of a script file is  pre‐\nsented on the tclsh command line, but the script file can always source it if desired.\n\nIf you create a Tcl script in a file whose first line is\n\n#!/usr/local/bin/tclsh\n\nthen  you  can  invoke  the script file directly from your shell if you mark the file as exe‐\ncutable.  This assumes that tclsh has been installed in  the  default  location  in  /usr/lo‐\ncal/bin;   if  it  is installed somewhere else then you will have to modify the above line to\nmatch.  Many UNIX systems do not allow the #! line to exceed about 30 characters  in  length,\nso be sure that the tclsh executable can be accessed with a short file name.\n\nAn even better approach is to start your script files with the following three lines:\n\n#!/bin/sh\n# the next line restarts using tclsh \\\nexec tclsh \"$0\" ${1+\"$@\"}\n\nThis  approach  has three advantages over the approach in the previous paragraph.  First, the\nlocation of the tclsh binary does not have to be hard-wired into the script:  it can be  any‐\nwhere  in your shell search path.  Second, it gets around the 30-character file name limit in\nthe previous approach.  Third, this approach will work even if tclsh is itself a shell script\n(this is done on some systems in order to handle multiple architectures or operating systems:\nthe tclsh script selects one of several binaries to run).  The three lines cause both sh  and\ntclsh  to  process  the script, but the exec is only executed by sh.  sh processes the script\nfirst;  it treats the second line as a comment and executes the third line.  The exec  state‐\nment cause the shell to stop processing and instead to start up tclsh to reprocess the entire\nscript.  When tclsh starts up, it treats all three lines as comments, since the backslash  at\nthe  end of the second line causes the third line to be treated as part of the comment on the\nsecond line.\n\nYou should note that it is also common practice to install tclsh with its version  number  as\npart  of  the  name.  This has the advantage of allowing multiple versions of Tcl to exist on\nthe same system at once, but also the disadvantage of making it harder to write scripts  that\nstart up uniformly across different versions of Tcl.\n",
            "subsections": []
        },
        "VARIABLES": {
            "content": "Tclsh sets the following global Tcl variables in addition to those created by the Tcl library\nitself (such as env, which maps environment variables such as PATH into Tcl):\n\nargc           Contains a count of the number of arg arguments (0 if none), not including the\nname of the script file.\n\nargv           Contains  a  Tcl  list  whose  elements are the arg arguments, in order, or an\nempty string if there are no arg arguments.\n\nargv0          Contains fileName if it was specified.  Otherwise, contains the name by  which\ntclsh was invoked.\n\ntclinteractive\nContains  1  if  tclsh is running interactively (no fileName was specified and\nstandard input is a terminal-like device), 0 otherwise.\n",
            "subsections": []
        },
        "PROMPTS": {
            "content": "When tclsh is invoked interactively it normally prompts for each command with “% ”.  You  can\nchange  the  prompt by setting the global variables tclprompt1 and tclprompt2.  If variable\ntclprompt1 exists then it must consist of a Tcl script to output a prompt;  instead of  out‐\nputting  a prompt tclsh will evaluate the script in tclprompt1.  The variable tclprompt2 is\nused in a similar way when a newline is typed but the current command is not yet complete; if\ntclprompt2 is not set then no prompt is output for incomplete commands.\n",
            "subsections": []
        },
        "STANDARD CHANNELS": {
            "content": "See TclStandardChannels for more explanations.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "autopath(3tcl), encoding(3tcl), env(3tcl), fconfigure(3tcl)\n",
            "subsections": []
        },
        "KEYWORDS": {
            "content": "application, argument, interpreter, prompt, script file, shell\n\n\n\nTcl                                                                                         tclsh(1)",
            "subsections": []
        }
    },
    "summary": "tclsh - Simple shell containing Tcl interpreter",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "autopath",
            "section": "3tcl",
            "url": "https://www.chedong.com/phpMan.php/man/autopath/3tcl/json"
        },
        {
            "name": "encoding",
            "section": "3tcl",
            "url": "https://www.chedong.com/phpMan.php/man/encoding/3tcl/json"
        },
        {
            "name": "env",
            "section": "3tcl",
            "url": "https://www.chedong.com/phpMan.php/man/env/3tcl/json"
        },
        {
            "name": "fconfigure",
            "section": "3tcl",
            "url": "https://www.chedong.com/phpMan.php/man/fconfigure/3tcl/json"
        }
    ]
}