Back: Functions
Forward: Test
 
FastBack: Test
Up: Sh Implementation
FastForward: Environment
Top: Autoconf, Automake, and Libtool
Contents: Table of Contents
Index: Index
About: About this document

22.2.5 .


The semantics of `.' are rather peculiar to say the least. Here is a simple script -- it just displays its positional parameters:

 
#! /bin/sh
echo "$0" ${1+"[email protected]"}

Put this in a file, `foo'. Here is another simple script -- it calls the first script. Put this in another file, `wrapper':

 
#! /bin/sh
. ./foo
. ./foo bar baz

Observe what happens when you run this from the command line:

 
$ ./wrapper
./wrapper
./wrapper bar baz

So `$0' is inherited from the calling script, and the positional parameters are as passed to the command. Observe what happens when you call the wrapper script with arguments:

 
$ ./wrapper 1 2 3
./wrapper 1 2 3
./wrapper bar baz

So the sourced script has access to the calling scripts positional parameters, unless you override them in the `.' command.

This can cause no end of trouble if you are not expecting it, so you must either be careful to omit all parameters to any `.' command, or else don't reference the parameters inside the sourced script. If you are reexecuting your script with a shell that understands functions, the best use for the `.' command is to load libraries of functions which can subsequently be used in the calling script.

Most importantly, don't forget that, if you call the exit command in a script that you load with `.', it will cause the calling script to exit too!



This document was generated by Gary V. Vaughan on February, 8 2006 using texi2html