Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between sourcing and executing a script?

Status
Not open for further replies.

goldenradium2001

Technical User
Mar 22, 2002
91
US
I understand that sourcing is:

source filename or . filename

And executing a script
./filename

What's the difference?
 
Hi:

During normal execution ./filename spawns a child process; changes to the environment, i.e. creating or modifying shell variables, changing to different directories, etc are discarded when the child terminates.

When sourcing a file:

source filename # csh, untested

or

. filename

update the parent shell.

Regards,

Ed
 


Also remember that a script normally has the first line describing what SHELL it is supposed to run in.


#! /bin/sh

#! /bin/csh

#! /usr/bin/perl


If you SOURCE or . the script and you are in the wrong SHELL the script may fail to execute properly.

A few people have tested there scripts via SOURCE or . and then when they run it it fails because it runs under the default SHELL which was different than where they tested it because they forgot to specify the SHELL on the first line of the script.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top