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 -rsrc resourceName ?fileName?
14
15 source -rsrcid resourceId ?fileName?
16_________________________________________________________________
17
18
20 This command takes the contents of the specified file or resource and
21 passes it to the Tcl interpreter as a text script. The return value
22 from source is the return value of the last command executed in the
23 script. If an error occurs in evaluating the contents of the script
24 then the source command will return that error. If a return command is
25 invoked from within the script then the remainder of the file will be
26 skipped and the source command will return normally with the result
27 from the return command.
28
29 The end-of-file character for files is '\32' (^Z) for all platforms. │
30 The source command will read files up to this character. This restric‐ │
31 tion does not exist for the read or gets commands, allowing for files │
32 containing code and data segments (scripted documents). If you require │
33 a ``^Z'' in code for string comparison, you can use ``\032'' or │
34 ``\u001a'', which will be safely substituted by the Tcl interpreter │
35 into ``^Z''.
36
37 The -rsrc and -rsrcid forms of this command are only available on Mac‐
38 intosh computers. These versions of the command allow you to source a
39 script from a TEXT resource. You may specify what TEXT resource to
40 source by either name or id. By default Tcl searches all open resource
41 files, which include the current application and any loaded C exten‐
42 sions. Alternatively, you may specify the fileName where the TEXT
43 resource can be found.
44
46 Run the script in the file foo.tcl and then the script in the file
47 bar.tcl:
48 source foo.tcl
49 source bar.tcl
50 Alternatively:
51 foreach scriptFile {foo.tcl bar.tcl} {
52 source $scriptFile
53 }
54
55
57 file(n), cd(n), info(n)
58
59
61 file, script
62
63
64
65Tcl source(n)