Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

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+"$@"}

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

 
 
  Published under the terms of the Open Publication License Design by Interspire