| [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 | 
|---|
 | 15 | tclsh \- 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 | 
|---|
 | 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, interactive \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 | .VS 8.5 | 
|---|
 | 37 | If \fBtclsh\fR is invoked with arguments then the first few arguments | 
|---|
 | 38 | specify the name of a script file, and, optionally, the encoding of | 
|---|
 | 39 | the text data stored in that script file.  | 
|---|
 | 40 | .VE 8.5 | 
|---|
 | 41 | Any additional arguments | 
|---|
 | 42 | are made available to the script as variables (see below). | 
|---|
 | 43 | Instead of reading commands from standard input \fBtclsh\fR will | 
|---|
 | 44 | read Tcl commands from the named file;  \fBtclsh\fR will exit | 
|---|
 | 45 | when it reaches the end of the file. | 
|---|
 | 46 | The end of the file may be marked either by the physical end of | 
|---|
 | 47 | the medium, or by the character, | 
|---|
 | 48 | .QW \e032 | 
|---|
 | 49 | .PQ \eu001a ", control-Z" . | 
|---|
 | 50 | If this character is present in the file, the \fBtclsh\fR application | 
|---|
 | 51 | will read text up to but not including the character.  An application | 
|---|
 | 52 | that requires this character in the file may safely encode it as | 
|---|
 | 53 | .QW \e032 , | 
|---|
 | 54 | .QW \ex1a , | 
|---|
 | 55 | or | 
|---|
 | 56 | .QW \eu001a ; | 
|---|
 | 57 | or may generate it by use of commands such as \fBformat\fR or \fBbinary\fR. | 
|---|
 | 58 | There is no automatic evaluation of \fB.tclshrc\fR when the name | 
|---|
 | 59 | of a script file is presented on the \fBtclsh\fR command | 
|---|
 | 60 | line, but the script file can always \fBsource\fR it if desired. | 
|---|
 | 61 | .PP | 
|---|
 | 62 | If you create a Tcl script in a file whose first line is | 
|---|
 | 63 | .CS | 
|---|
 | 64 | \fB#!/usr/local/bin/tclsh\fR | 
|---|
 | 65 | .CE | 
|---|
 | 66 | then you can invoke the script file directly from your shell if | 
|---|
 | 67 | you mark the file as executable. | 
|---|
 | 68 | This assumes that \fBtclsh\fR has been installed in the default | 
|---|
 | 69 | location in /usr/local/bin;  if it is installed somewhere else | 
|---|
 | 70 | then you will have to modify the above line to match. | 
|---|
 | 71 | Many UNIX systems do not allow the \fB#!\fR line to exceed about | 
|---|
 | 72 | 30 characters in length, so be sure that the \fBtclsh\fR | 
|---|
 | 73 | executable can be accessed with a short file name. | 
|---|
 | 74 | .PP | 
|---|
 | 75 | An even better approach is to start your script files with the | 
|---|
 | 76 | following three lines: | 
|---|
 | 77 | .CS | 
|---|
 | 78 | \fB#!/bin/sh | 
|---|
 | 79 | # the next line restarts using tclsh \e | 
|---|
 | 80 | exec tclsh "$0" "$@"\fR | 
|---|
 | 81 | .CE | 
|---|
 | 82 | This approach has three advantages over the approach in the previous | 
|---|
 | 83 | paragraph.  First, the location of the \fBtclsh\fR binary does not have | 
|---|
 | 84 | to be hard-wired into the script:  it can be anywhere in your shell | 
|---|
 | 85 | search path.  Second, it gets around the 30-character file name limit | 
|---|
 | 86 | in the previous approach. | 
|---|
 | 87 | Third, this approach will work even if \fBtclsh\fR is | 
|---|
 | 88 | itself a shell script (this is done on some systems in order to | 
|---|
 | 89 | handle multiple architectures or operating systems:  the \fBtclsh\fR | 
|---|
 | 90 | script selects one of several binaries to run).  The three lines | 
|---|
 | 91 | cause 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 | 
|---|
 | 94 | line as a comment and executes the third line. | 
|---|
 | 95 | The \fBexec\fR statement cause the shell to stop processing and | 
|---|
 | 96 | instead to start up \fBtclsh\fR to reprocess the entire script. | 
|---|
 | 97 | When \fBtclsh\fR starts up, it treats all three lines as comments, | 
|---|
 | 98 | since the backslash at the end of the second line causes the third | 
|---|
 | 99 | line to be treated as part of the comment on the second line. | 
|---|
 | 100 | .PP | 
|---|
 | 101 | You should note that it is also common practice to install tclsh with | 
|---|
 | 102 | its version number as part of the name.  This has the advantage of | 
|---|
 | 103 | allowing multiple versions of Tcl to exist on the same system at once, | 
|---|
 | 104 | but also the disadvantage of making it harder to write scripts that | 
|---|
 | 105 | start 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 | 
|---|
 | 112 | Contains a count of the number of \fIarg\fR arguments (0 if none), | 
|---|
 | 113 | not including the name of the script file. | 
|---|
 | 114 | .TP 15 | 
|---|
 | 115 | \fBargv\fR | 
|---|
 | 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 | Contains \fIfileName\fR if it was specified. | 
|---|
 | 121 | Otherwise, contains the name by which \fBtclsh\fR was invoked. | 
|---|
 | 122 | .TP 15 | 
|---|
 | 123 | \fBtcl_interactive\fR | 
|---|
 | 124 | Contains 1 if \fBtclsh\fR is running interactively (no | 
|---|
 | 125 | \fIfileName\fR was specified and standard input is a terminal-like | 
|---|
 | 126 | device), 0 otherwise. | 
|---|
 | 127 |  | 
|---|
 | 128 | .SH PROMPTS | 
|---|
 | 129 | .PP | 
|---|
 | 130 | When \fBtclsh\fR is invoked interactively it normally prompts for each | 
|---|
 | 131 | command with | 
|---|
 | 132 | .QW "\fB% \fR" . | 
|---|
 | 133 | You can change the prompt by setting the | 
|---|
 | 134 | variables \fBtcl_prompt1\fR and \fBtcl_prompt2\fR.  If variable | 
|---|
 | 135 | \fBtcl_prompt1\fR exists then it must consist of a Tcl script | 
|---|
 | 136 | to output a prompt;  instead of outputting a prompt \fBtclsh\fR | 
|---|
 | 137 | will evaluate the script in \fBtcl_prompt1\fR. | 
|---|
 | 138 | The variable \fBtcl_prompt2\fR is used in a similar way when | 
|---|
 | 139 | a newline is typed but the current command is not yet complete; | 
|---|
 | 140 | if \fBtcl_prompt2\fR is not set then no prompt is output for | 
|---|
 | 141 | incomplete commands. | 
|---|
 | 142 |  | 
|---|
 | 143 | .SH "STANDARD CHANNELS" | 
|---|
 | 144 | .PP | 
|---|
 | 145 | See \fBTcl_StandardChannels\fR for more explanations. | 
|---|
 | 146 |  | 
|---|
 | 147 | .SH "SEE ALSO" | 
|---|
 | 148 | encoding(n), fconfigure(n), tclvars(n) | 
|---|
 | 149 |  | 
|---|
 | 150 | .SH KEYWORDS | 
|---|
 | 151 | argument, interpreter, prompt, script file, shell | 
|---|