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
14

DESCRIPTION

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

SCRIPT FILES

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

VARIABLES

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

PROMPTS

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

STANDARD CHANNELS

113       See Tcl_StandardChannels for more explanations.
114
115

SEE ALSO

117       encoding(n), fconfigure(n), tclvars(n)
118
119

KEYWORDS

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