Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/tclsh.1 @ 33

Last change on this file since 33 was 25, checked in by landauf, 17 years ago

added tcl to libs

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