1<HTML><HEAD><TITLE>Built-In Commands - source manual page</TITLE></HEAD><BODY> 2<H3><A NAME="M2">NAME</A></H3> 3source - Evaluate a file or resource as a Tcl script 4<H3><A NAME="M3">SYNOPSIS</A></H3> 5<B>source </B><I>fileName</I><BR> 6<B>source</B> <B>-rsrc </B><I>resourceName </I>?<I>fileName</I>?<BR> 7<B>source</B> <B>-rsrcid </B><I>resourceId </I>?<I>fileName</I>?<BR> 8<H3><A NAME="M4">DESCRIPTION</A></H3> 9This command takes the contents of the specified file or resource 10and passes it to the Tcl interpreter as a text script. The return 11value from <B>source</B> is the return value of the last command 12executed in the script. If an error occurs in evaluating the contents 13of the script then the <B>source</B> command will return that error. 14If a <B><A HREF="../TclCmd/return.htm">return</A></B> command is invoked from within the script then the 15remainder of the file will be skipped and the <B>source</B> command 16will return normally with the result from the <B><A HREF="../TclCmd/return.htm">return</A></B> command. 17<P> 18The end-of-file character for files is '\32' (^Z) for all platforms. 19The source command will read files up to this character. This 20restriction does not exist for the <B><A HREF="../TclCmd/read.htm">read</A></B> or <B><A HREF="../TclCmd/gets.htm">gets</A></B> commands, 21allowing for files containing code and data segments (scripted documents). 22If you require a ``^Z'' in code for string comparison, you can use 23``\032'' or ``\u001a'', which will be safely substituted by the Tcl 24interpreter into ``^Z''. 25<H3><A NAME="M5">EXAMPLE</A></H3> 26Run the script in the file <B>foo.tcl</B> and then the script in the 27file <B>bar.tcl</B>: 28<PRE><B>source</B> foo.tcl 29<B>source</B> bar.tcl</PRE> 30Alternatively: 31<PRE>foreach scriptFile {foo.tcl bar.tcl} { 32 <B>source</B> $scriptFile 33}</PRE> 34<H3><A NAME="M6">SEE ALSO</A></H3> 35<B><A HREF="../TclCmd/file.htm">file</A></B>, <B><A HREF="../TclCmd/cd.htm">cd</A></B>, <B><A HREF="../TclCmd/info.htm">info</A></B> 36<H3><A NAME="M7">KEYWORDS</A></H3> 37<A href="../Keywords/F.htm#file">file</A>, <A href="../Keywords/S.htm#script">script</A> 38<HR><PRE> 39<A HREF="../copyright.htm">Copyright</A> © 1993 The Regents of the University of California. 40<A HREF="../copyright.htm">Copyright</A> © 1994-1996 Sun Microsystems, Inc. 41<A HREF="../copyright.htm">Copyright</A> © 2000 Scriptics Corporation. 42<A HREF="../copyright.htm">Copyright</A> © 1995-1997 Roger E. Critchlow Jr.</PRE> 43</BODY></HTML> 44