OSDN Git Service

Merge branch 'master' of git://github.com/monaka/binutils
[pf3gnuchains/pf3gnuchains3x.git] / tcl / doc / tclsh.1
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$
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
15 tclsh \- Simple shell containing Tcl interpreter
16 .SH SYNOPSIS
17 \fBtclsh\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
23 from its standard input or from a file and evaluates them.
24 If invoked with no arguments then it runs interactively, reading
25 Tcl commands from standard input and printing command results and
26 error messages to standard output.
27 It runs until the \fBexit\fR command is invoked or until it
28 reaches end-of-file on its standard input.
29 If there exists a file \fB.tclshrc\fR (or \fBtclshrc.tcl\fR on
30 the Windows platforms) in the home directory of
31 the user, \fBtclsh\fR evaluates the file as a Tcl script
32 just before reading the first command from standard input.
33
34 .SH "SCRIPT FILES"
35 .PP
36 If \fBtclsh\fR is invoked with arguments then the first argument
37 is the name of a script file and any additional arguments
38 are made available to the script as variables (see below).
39 Instead of reading commands from standard input \fBtclsh\fR will
40 read Tcl commands from the named file;  \fBtclsh\fR will exit
41 when it reaches the end of the file.
42 There is no automatic evaluation of \fB.tclshrc\fR in this
43 case, but the script file can always \fBsource\fR it if desired.
44 .PP
45 If you create a Tcl script in a file whose first line is
46 .CS
47 \fB#!/usr/local/bin/tclsh\fR
48 .CE
49 then you can invoke the script file directly from your shell if
50 you mark the file as executable.
51 This assumes that \fBtclsh\fR has been installed in the default
52 location in /usr/local/bin;  if it's installed somewhere else
53 then you'll have to modify the above line to match.
54 Many UNIX systems do not allow the \fB#!\fR line to exceed about
55 30 characters in length, so be sure that the \fBtclsh\fR
56 executable can be accessed with a short file name.
57 .PP
58 An even better approach is to start your script files with the
59 following three lines:
60 .CS
61 \fB#!/bin/sh
62 # the next line restarts using tclsh \e
63 exec tclsh "$0" "$@"\fR
64 .CE
65 This approach has three advantages over the approach in the previous
66 paragraph.  First, the location of the \fBtclsh\fR binary doesn't have
67 to be hard-wired into the script:  it can be anywhere in your shell
68 search path.  Second, it gets around the 30-character file name limit
69 in the previous approach.
70 Third, this approach will work even if \fBtclsh\fR is
71 itself a shell script (this is done on some systems in order to
72 handle multiple architectures or operating systems:  the \fBtclsh\fR
73 script selects one of several binaries to run).  The three lines
74 cause both \fBsh\fR and \fBtclsh\fR to process the script, but the
75 \fBexec\fR is only executed by \fBsh\fR.
76 \fBsh\fR processes the script first;  it treats the second
77 line as a comment and executes the third line.
78 The \fBexec\fR statement cause the shell to stop processing and
79 instead to start up \fBtclsh\fR to reprocess the entire script.
80 When \fBtclsh\fR starts up, it treats all three lines as comments,
81 since the backslash at the end of the second line causes the third
82 line to be treated as part of the comment on the second line.
83 .PP
84 .VS
85 You should note that it is also common practise to install tclsh with
86 its version number as part of the name.  This has the advantage of
87 allowing multiple versions of Tcl to exist on the same system at once,
88 but also the disadvantage of making it harder to write scripts that
89 start up uniformly across different versions of Tcl.
90 .VE
91
92 .SH "VARIABLES"
93 .PP
94 \fBTclsh\fR sets the following Tcl variables:
95 .TP 15
96 \fBargc\fR
97 Contains a count of the number of \fIarg\fR arguments (0 if none),
98 not including the name of the script file.
99 .TP 15
100 \fBargv\fR
101 Contains a Tcl list whose elements are the \fIarg\fR arguments,
102 in order, or an empty string if there are no \fIarg\fR arguments.
103 .TP 15
104 \fBargv0\fR
105 Contains \fIfileName\fR if it was specified.
106 Otherwise, contains the name by which \fBtclsh\fR was invoked.
107 .TP 15
108 \fBtcl_interactive\fR
109 Contains 1 if \fBtclsh\fR is running interactively (no
110 \fIfileName\fR was specified and standard input is a terminal-like
111 device), 0 otherwise.
112
113 .SH PROMPTS
114 .PP
115 When \fBtclsh\fR is invoked interactively it normally prompts for each
116 command with ``\fB% \fR''.  You can change the prompt by setting the
117 variables \fBtcl_prompt1\fR and \fBtcl_prompt2\fR.  If variable
118 \fBtcl_prompt1\fR exists then it must consist of a Tcl script
119 to output a prompt;  instead of outputting a prompt \fBtclsh\fR
120 will evaluate the script in \fBtcl_prompt1\fR.
121 The variable \fBtcl_prompt2\fR is used in a similar way when
122 a newline is typed but the current command isn't yet complete;
123 if \fBtcl_prompt2\fR isn't set then no prompt is output for
124 incomplete commands.
125
126 .SH "STANDARD CHANNELS"
127 .PP
128 See \fBTcl_StandardChannels\fR for more explanations.
129
130 .SH "SEE ALSO"
131 fconfigure(n), tclvars(n)
132
133 .SH KEYWORDS
134 argument, interpreter, prompt, script file, shell