Debian Codegraph @

doc/tclsh.1

raw
1 '\"
2 '\" Copyright (c) 1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4 '\"
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 '\"
8 .TH tclsh 1 "" Tcl "Tcl Applications"
9 .so man.macros
10 .BS
11 '\" Note: do not modify the .SH NAME line immediately below!
12 .SH NAME
13 tclsh \- Simple shell containing Tcl interpreter
14 .SH SYNOPSIS
15 \fBtclsh\fR ?\fB\-encoding \fIname\fR? ?\fIfileName arg arg ...\fR?
16 .BE
17 .SH DESCRIPTION
18 .PP
19 \fBTclsh\fR is a shell-like application that reads Tcl commands
20 from its standard input or from a file and evaluates them.
21 If invoked with no arguments then it runs interactively, reading
22 Tcl commands from standard input and printing command results and
23 error messages to standard output.
24 It runs until the \fBexit\fR command is invoked or until it
25 reaches end-of-file on its standard input.
26 If there exists a file \fB.tclshrc\fR (or \fBtclshrc.tcl\fR on
27 the Windows platforms) in the home directory of
28 the user, interactive \fBtclsh\fR evaluates the file as a Tcl script
29 just before reading the first command from standard input.
30 .SH "SCRIPT FILES"
31 .PP
32 If \fBtclsh\fR is invoked with arguments then the first few arguments
33 specify the name of a script file, and, optionally, the encoding of
34 the text data stored in that script file. Any additional arguments
35 are made available to the script as variables (see below).
36 Instead of reading commands from standard input \fBtclsh\fR will
37 read Tcl commands from the named file; \fBtclsh\fR will exit
38 when it reaches the end of the file.
39 The end of the file may be marked either by the physical end of
40 the medium, or by the character,
41 .QW \e032
42 .PQ \eu001a ", control-Z" .
43 If this character is present in the file, the \fBtclsh\fR application
44 will read text up to but not including the character. An application
45 that requires this character in the file may safely encode it as
46 .QW \e032 ,
47 .QW \ex1A ,
48 or
49 .QW \eu001a ;
50 or may generate it by use of commands such as \fBformat\fR or \fBbinary\fR.
51 There is no automatic evaluation of \fB.tclshrc\fR when the name
52 of a script file is presented on the \fBtclsh\fR command
53 line, but the script file can always \fBsource\fR it if desired.
54 .PP
55 If you create a Tcl script in a file whose first line is
56 .PP
57 .CS
58 \fB#!/usr/local/bin/tclsh\fR
59 .CE
60 .PP
61 then you can invoke the script file directly from your shell if
62 you mark the file as executable.
63 This assumes that \fBtclsh\fR has been installed in the default
64 location in /usr/local/bin; if it is installed somewhere else
65 then you will have to modify the above line to match.
66 Many UNIX systems do not allow the \fB#!\fR line to exceed about
67 30 characters in length, so be sure that the \fBtclsh\fR
68 executable can be accessed with a short file name.
69 .PP
70 An even better approach is to start your script files with the
71 following three lines:
72 .PP
73 .CS
74 \fB#!/bin/sh
75 # the next line restarts using tclsh \e
76 exec tclsh "$0" ${1+"$@"}\fR
77 .CE
78 .PP
79 This approach has three advantages over the approach in the previous
80 paragraph. First, the location of the \fBtclsh\fR binary does not have
81 to be hard-wired into the script: it can be anywhere in your shell
82 search path. Second, it gets around the 30-character file name limit
83 in the previous approach.
84 Third, this approach will work even if \fBtclsh\fR is
85 itself a shell script (this is done on some systems in order to
86 handle multiple architectures or operating systems: the \fBtclsh\fR
87 script selects one of several binaries to run). The three lines
88 cause both \fBsh\fR and \fBtclsh\fR to process the script, but the
89 \fBexec\fR is only executed by \fBsh\fR.
90 \fBsh\fR processes the script first; it treats the second
91 line as a comment and executes the third line.
92 The \fBexec\fR statement cause the shell to stop processing and
93 instead to start up \fBtclsh\fR to reprocess the entire script.
94 When \fBtclsh\fR starts up, it treats all three lines as comments,
95 since the backslash at the end of the second line causes the third
96 line to be treated as part of the comment on the second line.
97 .PP
98 You should note that it is also common practice to install tclsh with
99 its version number as part of the name. This has the advantage of
100 allowing multiple versions of Tcl to exist on the same system at once,
101 but also the disadvantage of making it harder to write scripts that
102 start up uniformly across different versions of Tcl.
103 .SH "VARIABLES"
104 .PP
105 \fBTclsh\fR sets the following global Tcl variables in addition to those
106 created by the Tcl library itself (such as \fBenv\fR, which maps
107 environment variables such as \fBPATH\fR into Tcl):
108 .TP 15
109 \fBargc\fR
110 .
111 Contains a count of the number of \fIarg\fR arguments (0 if none),
112 not including the name of the script file.
113 .TP 15
114 \fBargv\fR
115 .
116 Contains a Tcl list whose elements are the \fIarg\fR arguments,
117 in order, or an empty string if there are no \fIarg\fR arguments.
118 .TP 15
119 \fBargv0\fR
120 .
121 Contains \fIfileName\fR if it was specified.
122 Otherwise, contains the name by which \fBtclsh\fR was invoked.
123 .TP 15
124 \fBtcl_interactive\fR
125 .
126 Contains 1 if \fBtclsh\fR is running interactively (no
127 \fIfileName\fR was specified and standard input is a terminal-like
128 device), 0 otherwise.
129 .SH PROMPTS
130 .PP
131 When \fBtclsh\fR is invoked interactively it normally prompts for each
132 command with
133 .QW "\fB% \fR" .
134 You can change the prompt by setting the global
135 variables \fBtcl_prompt1\fR and \fBtcl_prompt2\fR. If variable
136 \fBtcl_prompt1\fR exists then it must consist of a Tcl script
137 to output a prompt; instead of outputting a prompt \fBtclsh\fR
138 will evaluate the script in \fBtcl_prompt1\fR.
139 The variable \fBtcl_prompt2\fR is used in a similar way when
140 a newline is typed but the current command is not yet complete;
141 if \fBtcl_prompt2\fR is not set then no prompt is output for
142 incomplete commands.
143 .SH "STANDARD CHANNELS"
144 .PP
145 See \fBTcl_StandardChannels\fR for more explanations.
146 .SH "SEE ALSO"
147 auto_path(n), encoding(n), env(n), fconfigure(n)
148 .SH KEYWORDS
149 application, argument, interpreter, prompt, script file, shell