<HTML ><HEAD ><TITLE >Sourcing a File</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Bash Prompt HOWTO" HREF="index.html"><LINK REL="UP" TITLE="Bash Programming and Shell Scripts" HREF="c189.html"><LINK REL="PREVIOUS" TITLE="Non-Printing Characters in Prompts" HREF="nonprintingchars.html"><LINK REL="NEXT" TITLE="Functions, Aliases, and the Environment" HREF="x246.html"></HEAD ><BODY CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Bash Prompt HOWTO: </TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="nonprintingchars.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 3. Bash Programming and Shell Scripts</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="x246.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="AEN237" ></A >3.5. Sourcing a File</H1 ><P >When a file is sourced (by typing either <TT CLASS="USERINPUT" ><B >source filename</B ></TT > or <TT CLASS="USERINPUT" ><B >. filename</B ></TT > at the command line), the lines of code in the file are executed as if they were printed at the command line. This is particularly useful with complex prompts, to allow them to be stored in files and called up by sourcing the file they are in. </P ><P >In examples, you will find that I often include <TT CLASS="USERINPUT" ><B >#!/bin/bash</B ></TT > at the beginning of files including functions. This is <EM >not</EM > necessary if you are sourcing a file, just as it isn't necessary to <TT CLASS="USERINPUT" ><B >chmod +x</B ></TT > a file that is going to be sourced. I do this because it makes Vim (my editor of choice, no flames please - you use what you like) think I'm editing a shell script and turn on colour syntax highlighting. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="nonprintingchars.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="x246.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Non-Printing Characters in Prompts</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="c189.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Functions, Aliases, and the Environment</TD ></TR ></TABLE ></DIV ></BODY ></HTML >