| 1 | '\" | 
|---|
| 2 | '\" Copyright (c) 1993 The Regents of the University of California. | 
|---|
| 3 | '\" Copyright (c) 1994-1996 Sun Microsystems, Inc. | 
|---|
| 4 | '\" Copyright (c) 2000 Scriptics Corporation. | 
|---|
| 5 | '\" | 
|---|
| 6 | '\" See the file "license.terms" for information on usage and redistribution | 
|---|
| 7 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. | 
|---|
| 8 | '\"  | 
|---|
| 9 | '\" RCS: @(#) $Id: source.n,v 1.18 2007/12/13 15:22:33 dgp Exp $ | 
|---|
| 10 | '\"  | 
|---|
| 11 | .so man.macros | 
|---|
| 12 | .TH source n "" Tcl "Tcl Built-In Commands" | 
|---|
| 13 | .BS | 
|---|
| 14 | '\" Note:  do not modify the .SH NAME line immediately below! | 
|---|
| 15 | .SH NAME | 
|---|
| 16 | source \- Evaluate a file or resource as a Tcl script | 
|---|
| 17 | .SH SYNOPSIS | 
|---|
| 18 | \fBsource \fIfileName\fR | 
|---|
| 19 | .sp | 
|---|
| 20 | .VS 8.5 | 
|---|
| 21 | \fBsource\fR \fB\-encoding \fIencodingName fileName\fR | 
|---|
| 22 | .VE 8.5 | 
|---|
| 23 | .BE | 
|---|
| 24 | .SH DESCRIPTION | 
|---|
| 25 | .PP | 
|---|
| 26 | This command takes the contents of the specified file or resource | 
|---|
| 27 | and passes it to the Tcl interpreter as a text script.  The return | 
|---|
| 28 | value from \fBsource\fR is the return value of the last command | 
|---|
| 29 | executed in the script.  If an error occurs in evaluating the contents | 
|---|
| 30 | of the script then the \fBsource\fR command will return that error. | 
|---|
| 31 | If a \fBreturn\fR command is invoked from within the script then the | 
|---|
| 32 | remainder of the file will be skipped and the \fBsource\fR command | 
|---|
| 33 | will return normally with the result from the \fBreturn\fR command. | 
|---|
| 34 | .PP | 
|---|
| 35 | The end-of-file character for files is | 
|---|
| 36 | .QW \e32 | 
|---|
| 37 | (^Z) for all platforms. | 
|---|
| 38 | The source command will read files up to this character.  This | 
|---|
| 39 | restriction does not exist for the \fBread\fR or \fBgets\fR commands, | 
|---|
| 40 | allowing for files containing code and data segments (scripted documents). | 
|---|
| 41 | If you require a | 
|---|
| 42 | .QW ^Z | 
|---|
| 43 | in code for string comparison, you can use | 
|---|
| 44 | .QW \e032 | 
|---|
| 45 | or | 
|---|
| 46 | .QW \eu001a , | 
|---|
| 47 | which will be safely substituted by the Tcl interpreter into | 
|---|
| 48 | .QW ^Z . | 
|---|
| 49 | .PP | 
|---|
| 50 | .VS 8.5 | 
|---|
| 51 | The \fB\-encoding\fR option is used to specify the encoding of | 
|---|
| 52 | the data stored in \fIfileName\fR.  When the \fB\-encoding\fR option | 
|---|
| 53 | is omitted, the system encoding is assumed. | 
|---|
| 54 | .VE 8.5 | 
|---|
| 55 | .SH EXAMPLE | 
|---|
| 56 | Run the script in the file \fBfoo.tcl\fR and then the script in the | 
|---|
| 57 | file \fBbar.tcl\fR: | 
|---|
| 58 | .CS | 
|---|
| 59 | \fBsource\fR foo.tcl | 
|---|
| 60 | \fBsource\fR bar.tcl | 
|---|
| 61 | .CE | 
|---|
| 62 | Alternatively: | 
|---|
| 63 | .CS | 
|---|
| 64 | foreach scriptFile {foo.tcl bar.tcl} { | 
|---|
| 65 |    \fBsource\fR $scriptFile | 
|---|
| 66 | } | 
|---|
| 67 | .CE | 
|---|
| 68 | .SH "SEE ALSO" | 
|---|
| 69 | file(n), cd(n), encoding(n), info(n) | 
|---|
| 70 | .SH KEYWORDS | 
|---|
| 71 | file, script | 
|---|