1source(n) Tcl Built-In Commands source(n)
2
3
4
5______________________________________________________________________________
6
8 source - Evaluate a file or resource as a Tcl script
9
11 source fileName
12
13 source -encoding encodingName fileName
14______________________________________________________________________________
15
17 This command takes the contents of the specified file or resource and
18 passes it to the Tcl interpreter as a text script. The return value
19 from source is the return value of the last command executed in the
20 script. If an error occurs in evaluating the contents of the script
21 then the source command will return that error. If a return command is
22 invoked from within the script then the remainder of the file will be
23 skipped and the source command will return normally with the result
24 from the return command.
25
26 The end-of-file character for files is “\32” (^Z) for all platforms.
27 The source command will read files up to this character. This restric‐
28 tion does not exist for the read or gets commands, allowing for files
29 containing code and data segments (scripted documents). If you require
30 a “^Z” in code for string comparison, you can use “\032” or “\u001a”,
31 which will be safely substituted by the Tcl interpreter into “^Z”.
32
33 A leading BOM (Byte order mark) contained in the file is ignored for
34 unicode encodings (utf-8, unicode).
35
36 The -encoding option is used to specify the encoding of the data stored
37 in fileName. When the -encoding option is omitted, the system encoding
38 is assumed.
39
41 Run the script in the file foo.tcl and then the script in the file
42 bar.tcl:
43
44 source foo.tcl
45 source bar.tcl
46
47 Alternatively:
48
49 foreach scriptFile {foo.tcl bar.tcl} {
50 source $scriptFile
51 }
52
54 file(n), cd(n), encoding(n), info(n)
55
57 file, script
58
59
60
61Tcl source(n)