Debian Codegraph @

doc/set.n

raw
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 .TH set n "" Tcl "Tcl Built-In Commands"
9 .so man.macros
10 .BS
11 '\" Note: do not modify the .SH NAME line immediately below!
12 .SH NAME
13 set \- Read and write variables
14 .SH SYNOPSIS
15 \fBset \fIvarName \fR?\fIvalue\fR?
16 .BE
17 .SH DESCRIPTION
18 .PP
19 Returns the value of variable \fIvarName\fR.
20 If \fIvalue\fR is specified, then set
21 the value of \fIvarName\fR to \fIvalue\fR, creating a new variable
22 if one does not already exist, and return its value.
23 If \fIvarName\fR contains an open parenthesis and ends with a
24 close parenthesis, then it refers to an array element: the characters
25 before the first open parenthesis are the name of the array,
26 and the characters between the parentheses are the index within the array.
27 Otherwise \fIvarName\fR refers to a scalar variable.
28 .PP
29 If \fIvarName\fR includes namespace qualifiers
30 (in the array name if it refers to an array element), or if \fIvarName\fR
31 is unqualified (does not include the names of any containing namespaces)
32 but no procedure is active,
33 \fIvarName\fR refers to a namespace variable
34 resolved according to the rules described under \fBNAME RESOLUTION\fR in
35 the \fBnamespace\fR manual page.
36 .PP
37 If a procedure is active and \fIvarName\fR is unqualified, then
38 \fIvarName\fR refers to a parameter or local variable of the procedure,
39 unless \fIvarName\fR was declared to resolve differently through one of the
40 \fBglobal\fR, \fBvariable\fR or \fBupvar\fR commands.
41 .SH EXAMPLES
42 .PP
43 Store a random number in the variable \fIr\fR:
44 .PP
45 .CS
46 \fBset\fR r [expr {rand()}]
47 .CE
48 .PP
49 Store a short message in an array element:
50 .PP
51 .CS
52 \fBset\fR anAry(msg) "Hello, World!"
53 .CE
54 .PP
55 Store a short message in an array element specified by a variable:
56 .PP
57 .CS
58 \fBset\fR elemName "msg"
59 \fBset\fR anAry($elemName) "Hello, World!"
60 .CE
61 .PP
62 Copy a value into the variable \fIout\fR from a variable whose name is
63 stored in the \fIvbl\fR (note that it is often easier to use arrays in
64 practice instead of doing double-dereferencing):
65 .PP
66 .CS
67 \fBset\fR in0 "small random"
68 \fBset\fR in1 "large random"
69 \fBset\fR vbl in[expr {rand() >= 0.5}]
70 \fBset\fR out [\fBset\fR $vbl]
71 .CE
72 .SH "SEE ALSO"
73 expr(n), global(n), namespace(n), proc(n), trace(n), unset(n), upvar(n), variable(n)
74 .SH KEYWORDS
75 read, write, variable