Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / share / tcl / help / tcl / intro / tclsh
1 NAME
2 tclsh - Simple shell containing Tcl interpreter
3
4 SYNOPSIS
5 tclsh ?fileName arg arg ...?
6
7
8 DESCRIPTION
9 Tclsh is a shell-like application that reads Tcl commands from its
10 standard input or from a file and evaluates them. If invoked with no
11 arguments then it runs interactively, reading Tcl commands from stan-
12 dard input and printing command results and error messages to standard
13 output. It runs until the exit command is invoked or until it reaches
14 end-of-file on its standard input. If there exists a file .tclshrc (or
15 tclshrc.tcl on the Windows platforms) in the home directory of the
16 user, tclsh evaluates the file as a Tcl script just before reading the
17 first command from standard input.
18
19
20 SCRIPT FILES
21 If tclsh is invoked with arguments then the first argument is the name
22 of a script file and any additional arguments are made available to the
23 script as variables (see below). Instead of reading commands from
24 standard input tclsh will read Tcl commands from the named file; tclsh
25 will exit when it reaches the end of the file. The end of the file may
26 be marked either by the physical end of the medium, or by the charac-
27 ter, '\032' ('\u001a', control-Z). If this character is present in the
28 file, the tclsh application will read text up to but not including the
29 character. An application that requires this character in the file may
30 safely encode it as ``\032'', ``\x1a'', or ``\u001a''; or may generate
31 it by use of commands such as format or binary. There is no automatic
32 evaluation of .tclshrc when the name of a script file is presented on
33 the tclsh command line, but the script file can always source it if
34 desired.
35
36 If you create a Tcl script in a file whose first line is
37 #!/usr/local/bin/tclsh
38 then you can invoke the script file directly from your shell if you
39 mark the file as executable. This assumes that tclsh has been
40 installed in the default location in /usr/local/bin; if it's installed
41 somewhere else then you'll have to modify the above line to match.
42 Many UNIX systems do not allow the #! line to exceed about 30 charac-
43 ters in length, so be sure that the tclsh executable can be accessed
44 with a short file name.
45
46 An even better approach is to start your script files with the follow-
47 ing three lines:
48 #!/bin/sh
49 # the next line restarts using tclsh \
50 exec tclsh "$0" "$@"
51 This approach has three advantages over the approach in the previous
52 paragraph. First, the location of the tclsh binary doesn't have to be
53 hard-wired into the script: it can be anywhere in your shell search
54 path. Second, it gets around the 30-character file name limit in the
55 previous approach. Third, this approach will work even if tclsh is
56 itself a shell script (this is done on some systems in order to handle
57 multiple architectures or operating systems: the tclsh script selects
58 one of several binaries to run). The three lines cause both sh and
59 tclsh to process the script, but the exec is only executed by sh. sh
60 processes the script first; it treats the second line as a comment and
61 executes the third line. The exec statement cause the shell to stop
62 processing and instead to start up tclsh to reprocess the entire
63 script. When tclsh starts up, it treats all three lines as comments,
64 since the backslash at the end of the second line causes the third line
65 to be treated as part of the comment on the second line.
66
67 You should note that it is also common practise to install tclsh with
68 its version number as part of the name. This has the advantage of
69 allowing multiple versions of Tcl to exist on the same system at once,
70 but also the disadvantage of making it harder to write scripts that
71 start up uniformly across different versions of Tcl.
72
73
74 VARIABLES
75 Tclsh sets the following Tcl variables:
76
77 argc Contains a count of the number of arg arguments (0 if
78 none), not including the name of the script file.
79
80 argv Contains a Tcl list whose elements are the arg argu-
81 ments, in order, or an empty string if there are no arg
82 arguments.
83
84 argv0 Contains fileName if it was specified. Otherwise, con-
85 tains the name by which tclsh was invoked.
86
87 tcl_interactive
88 Contains 1 if tclsh is running interactively (no file-
89 Name was specified and standard input is a terminal-like
90 device), 0 otherwise.
91
92
93 PROMPTS
94 When tclsh is invoked interactively it normally prompts for each com-
95 mand with ``% ''. You can change the prompt by setting the variables
96 tcl_prompt1 and tcl_prompt2. If variable tcl_prompt1 exists then it
97 must consist of a Tcl script to output a prompt; instead of outputting
98 a prompt tclsh will evaluate the script in tcl_prompt1. The variable
99 tcl_prompt2 is used in a similar way when a newline is typed but the
100 current command isn't yet complete; if tcl_prompt2 isn't set then no
101 prompt is output for incomplete commands.
102
103
104 STANDARD CHANNELS
105 See Tcl_StandardChannels for more explanations.
106
107
108 SEE ALSO
109 fconfigure(n), tclvars(n)
110
111
112 KEYWORDS