22.2.5 .

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

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

 
 #! /bin/sh echo " 
 #! /bin/sh echo "$0" ${1+"$@"} 
" ${1+"$@"}

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 May, 24 2001 using texi2html


GNU Autoconf, Automake and Libtool
GNU Autoconf, Automake, and Libtool
ISBN: 1578701902
EAN: 2147483647
Year: 2002
Pages: 290

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net