version 1 showing authors affecting page license.
.
Rev |
Author |
# |
Line |
1 |
perry |
1 |
tclsh |
|
|
2 |
!!!tclsh |
|
|
3 |
NAME |
|
|
4 |
SYNOPSIS |
|
|
5 |
DESCRIPTION |
|
|
6 |
SCRIPT FILES |
|
|
7 |
VARIABLES |
|
|
8 |
PROMPTS |
|
|
9 |
KEYWORDS |
|
|
10 |
---- |
|
|
11 |
!!NAME |
|
|
12 |
|
|
|
13 |
|
|
|
14 |
tclsh - Simple shell containing Tcl interpreter |
|
|
15 |
!!SYNOPSIS |
|
|
16 |
|
|
|
17 |
|
|
|
18 |
__tclsh__ ?''fileName arg arg ...''? |
|
|
19 |
|
|
|
20 |
|
|
|
21 |
________________________________________________________________________________________________________________________________________ |
|
|
22 |
!!DESCRIPTION |
|
|
23 |
|
|
|
24 |
|
|
|
25 |
__Tclsh__ is a shell-like application that reads Tcl |
|
|
26 |
commands from its standard input or from a file and |
|
|
27 |
evaluates them. If invoked with no arguments then it runs |
|
|
28 |
interactively, reading Tcl commands from standard input and |
|
|
29 |
printing command results and error messages to standard |
|
|
30 |
output. It runs until the __exit__ command is invoked or |
|
|
31 |
until it reaches end-of-file on its standard input. If there |
|
|
32 |
exists a file __.tclshrc__ (or __tclshrc.tcl__ on the |
|
|
33 |
Windows platforms) in the home directory of the user, |
|
|
34 |
__tclsh__ evaluates the file as a Tcl script just before |
|
|
35 |
reading the first command from standard input. |
|
|
36 |
!!SCRIPT FILES |
|
|
37 |
|
|
|
38 |
|
|
|
39 |
If __tclsh__ is invoked with arguments then the first |
|
|
40 |
argument is the name of a script file and any additional |
|
|
41 |
arguments are made available to the script as variables (see |
|
|
42 |
below). Instead of reading commands from standard input |
|
|
43 |
__tclsh__ will read Tcl commands from the named file; |
|
|
44 |
__tclsh__ will exit when it reaches the end of the file. |
|
|
45 |
There is no automatic evaluation of __.tclshrc__ in this |
|
|
46 |
case, but the script file can always __source__ it if |
|
|
47 |
desired. |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
If you create a Tcl script in a file whose first line |
|
|
51 |
is |
|
|
52 |
|
|
|
53 |
|
|
|
54 |
__#!/usr/local/bin/tclsh |
|
|
55 |
__ |
|
|
56 |
|
|
|
57 |
|
|
|
58 |
then you can invoke the script file directly from your shell |
|
|
59 |
if you mark the file as executable. This assumes that |
|
|
60 |
__tclsh__ has been installed in the default location in |
|
|
61 |
/usr/local/bin; if it's installed somewhere else then you'll |
|
|
62 |
have to modify the above line to match. Many UNIX systems do |
|
|
63 |
not allow the __#!__ line to exceed about 30 characters |
|
|
64 |
in length, so be sure that the __tclsh__ executable can |
|
|
65 |
be accessed with a short file name. |
|
|
66 |
|
|
|
67 |
|
|
|
68 |
An even better approach is to start your script files with |
|
|
69 |
the following three lines: |
|
|
70 |
|
|
|
71 |
|
|
|
72 |
__#!/bin/sh |
|
|
73 |
# the next line restarts using tclsh \ |
|
|
74 |
exec tclsh |
|
|
75 |
__ |
|
|
76 |
|
|
|
77 |
|
|
|
78 |
This approach has three advantages over the approach in the |
|
|
79 |
previous paragraph. First, the location of the __tclsh__ |
|
|
80 |
binary doesn't have to be hard-wired into the script: it can |
|
|
81 |
be anywhere in your shell search path. Second, it gets |
|
|
82 |
around the 30-character file name limit in the previous |
|
|
83 |
approach. Third, this approach will work even if |
|
|
84 |
__tclsh__ is itself a shell script (this is done on some |
|
|
85 |
systems in order to handle multiple architectures or |
|
|
86 |
operating systems: the __tclsh__ script selects one of |
|
|
87 |
several binaries to run). The three lines cause both |
|
|
88 |
__sh__ and __tclsh__ to process the script, but the |
|
|
89 |
__exec__ is only executed by __sh__. __sh__ |
|
|
90 |
processes the script first; it treats the second line as a |
|
|
91 |
comment and executes the third line. The __exec__ |
|
|
92 |
statement cause the shell to stop processing and instead to |
|
|
93 |
start up __tclsh__ to reprocess the entire script. When |
|
|
94 |
__tclsh__ starts up, it treats all three lines as |
|
|
95 |
comments, since the backslash at the end of the second line |
|
|
96 |
causes the third line to be treated as part of the comment |
|
|
97 |
on the second line. |
|
|
98 |
!!VARIABLES |
|
|
99 |
|
|
|
100 |
|
|
|
101 |
__Tclsh__ sets the following Tcl variables: |
|
|
102 |
|
|
|
103 |
|
|
|
104 |
__argc__ Contains a count of the number of ''arg'' |
|
|
105 |
arguments (0 if none), not including the name of the script |
|
|
106 |
file. |
|
|
107 |
|
|
|
108 |
|
|
|
109 |
__argv__ Contains a Tcl list whose elements are the |
|
|
110 |
''arg'' arguments, in order, or an empty string if there |
|
|
111 |
are no ''arg'' arguments. |
|
|
112 |
|
|
|
113 |
|
|
|
114 |
__argv0__ Contains ''fileName'' if it was specified. |
|
|
115 |
Otherwise, contains the name by which __tclsh__ was |
|
|
116 |
invoked. |
|
|
117 |
|
|
|
118 |
|
|
|
119 |
__tcl_interactive__ |
|
|
120 |
|
|
|
121 |
|
|
|
122 |
Contains 1 if __tclsh__ is running interactively (no |
|
|
123 |
''fileName'' was specified and standard input is a |
|
|
124 |
terminal-like device), 0 otherwise. |
|
|
125 |
!!PROMPTS |
|
|
126 |
|
|
|
127 |
|
|
|
128 |
When __tclsh__ is invoked interactively it normally |
|
|
129 |
prompts for each command with ``__%__ ''. You can change |
|
|
130 |
the prompt by setting the variables __tcl_prompt1__ and |
|
|
131 |
__tcl_prompt2__. If variable __tcl_prompt1__ exists |
|
|
132 |
then it must consist of a Tcl script to output a prompt; |
|
|
133 |
instead of outputting a prompt __tclsh__ will evaluate |
|
|
134 |
the script in __tcl_prompt1__. The variable |
|
|
135 |
__tcl_prompt2__ is used in a similar way when a newline |
|
|
136 |
is typed but the current command isn't yet complete; if |
|
|
137 |
__tcl_prompt2__ isn't set then no prompt is output for |
|
|
138 |
incomplete commands. |
|
|
139 |
!!KEYWORDS |
|
|
140 |
|
|
|
141 |
|
|
|
142 |
argument, interpreter, prompt, script file, |
|
|
143 |
shell |
|
|
144 |
---- |