1tclsh(1)                       Tcl Applications                       tclsh(1)
2
3
4
5______________________________________________________________________________
6

NAME

8       tclsh - Simple shell containing Tcl interpreter
9

SYNOPSIS

11       tclsh ?-encoding name? ?fileName arg arg ...?
12______________________________________________________________________________
13

DESCRIPTION

15       Tclsh  is  a  shell-like  application  that reads Tcl commands from its
16       standard input or from a file and evaluates them.  If invoked  with  no
17       arguments  then  it runs interactively, reading Tcl commands from stan‐
18       dard input and printing command results and error messages to  standard
19       output.   It runs until the exit command is invoked or until it reaches
20       end-of-file on its standard input.  If there exists a file .tclshrc (or
21       tclshrc.tcl  on  the  Windows  platforms)  in the home directory of the
22       user, interactive tclsh evaluates the file as a Tcl script just  before
23       reading the first command from standard input.
24

SCRIPT FILES

26       If tclsh is invoked with arguments then the first few arguments specify
27       the name of a script file, and, optionally, the encoding  of  the  text
28       data  stored  in  that  script  file. Any additional arguments are made
29       available to the script as variables (see below).  Instead  of  reading
30       commands  from  standard  input  tclsh  will read Tcl commands from the
31       named file;  tclsh will exit when it reaches the end of the file.   The
32       end of the file may be marked either by the physical end of the medium,
33       or by the character, “\032” (“\u001a”, control-Z).  If  this  character
34       is  present in the file, the tclsh application will read text up to but
35       not including the character.  An application that requires this charac‐
36       ter in the file may safely encode it as “\032”, “\x1a”, or “\u001a”; or
37       may generate it by use of commands such as format or binary.  There  is
38       no  automatic  evaluation of .tclshrc when the name of a script file is
39       presented on the tclsh command line, but the  script  file  can  always
40       source it if desired.
41
42       If you create a Tcl script in a file whose first line is
43
44              #!/usr/local/bin/tclsh
45
46       then  you  can  invoke  the script file directly from your shell if you
47       mark the  file  as  executable.   This  assumes  that  tclsh  has  been
48       installed  in  the  default  location  in  /usr/local/bin;   if  it  is
49       installed somewhere else then you will have to modify the above line to
50       match.   Many  UNIX systems do not allow the #! line to exceed about 30
51       characters in length, so be sure  that  the  tclsh  executable  can  be
52       accessed with a short file name.
53
54       An  even better approach is to start your script files with the follow‐
55       ing three lines:
56
57              #!/bin/sh
58              # the next line restarts using tclsh \
59              exec tclsh "$0" ${1+"$@"}
60
61       This approach has three advantages over the approach  in  the  previous
62       paragraph.  First, the location of the tclsh binary does not have to be
63       hard-wired into the script:  it can be anywhere in  your  shell  search
64       path.   Second,  it gets around the 30-character file name limit in the
65       previous approach.  Third, this approach will work  even  if  tclsh  is
66       itself  a shell script (this is done on some systems in order to handle
67       multiple architectures or operating systems:  the tclsh script  selects
68       one  of  several  binaries  to run).  The three lines cause both sh and
69       tclsh to process the script, but the exec is only executed by  sh.   sh
70       processes the script first;  it treats the second line as a comment and
71       executes the third line.  The exec statement cause the  shell  to  stop
72       processing  and  instead  to  start  up  tclsh  to reprocess the entire
73       script.  When tclsh starts up, it treats all three lines  as  comments,
74       since the backslash at the end of the second line causes the third line
75       to be treated as part of the comment on the second line.
76
77       You should note that it is also common practice to install  tclsh  with
78       its  version  number  as  part  of the name.  This has the advantage of
79       allowing multiple versions of Tcl to exist on the same system at  once,
80       but  also  the  disadvantage  of making it harder to write scripts that
81       start up uniformly across different versions of Tcl.
82

VARIABLES

84       Tclsh sets the following global Tcl variables in addition to those cre‐
85       ated  by  the  Tcl  library itself (such as env, which maps environment
86       variables such as PATH into Tcl):
87
88       argc           Contains a count of the number of arg  arguments  (0  if
89                      none), not including the name of the script file.
90
91       argv           Contains  a  Tcl  list  whose elements are the arg argu‐
92                      ments, in order, or an empty string if there are no  arg
93                      arguments.
94
95       argv0          Contains  fileName if it was specified.  Otherwise, con‐
96                      tains the name by which tclsh was invoked.
97
98       tcl_interactive
99                      Contains 1 if tclsh is running interactively  (no  file‐
100                      Name was specified and standard input is a terminal-like
101                      device), 0 otherwise.
102

PROMPTS

104       When tclsh is invoked interactively it normally prompts for  each  com‐
105       mand  with “% ”.  You can change the prompt by setting the global vari‐
106       ables tcl_prompt1 and tcl_prompt2.  If variable tcl_prompt1 exists then
107       it  must  consist  of a Tcl script to output a prompt;  instead of out‐
108       putting a prompt tclsh will evaluate the script  in  tcl_prompt1.   The
109       variable  tcl_prompt2  is used in a similar way when a newline is typed
110       but the current command is not yet complete; if tcl_prompt2 is not  set
111       then no prompt is output for incomplete commands.
112

STANDARD CHANNELS

114       See Tcl_StandardChannels for more explanations.
115

SEE ALSO

117       auto_path(n), encoding(n), env(n), fconfigure(n)
118

KEYWORDS

120       application, argument, interpreter, prompt, script file, shell
121
122
123
124Tcl                                                                   tclsh(1)
Impressum