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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Methods of Executing a Script

Status
Not open for further replies.

peopleperson88

Technical User
Aug 8, 2002
46
US
I was working on a Solaris machine with a associate of mine and we came across an interesting feature. We were attempting to run a script and I accidently typed a "." in front of the script. It did something funky but I'm not sure what. Then I did some further research and found these three way to execute a script.

The script is called propogate.ksh. and these are the three methods that I used to execute them.

$ ksh propogate.ksh
$ . propogate.ksh
$ propogate.ksh


My question is....what are the differences between these three methods?

Thanks for any help. This is troubling my mind and I can't find any research on it.

Thanks
 
Hi peopleperson88,

if the current directory (where the script resides) is in your search path ($PATH) then you can execute the script with
$ propogate.ksh
If not you can either execute them by invoking the script as the first argument to a subshell
$ ksh propogate.ksh
or by executing it explicitly from the current directory
$ ./propogate.ksh
That is the same as if you typed in the absolute path.

When you accidentally typed
$ . propogate.ksh
you have acctually read in the script into ksh. The shell executes all commands in the script as if you typed them on the command line. This is done in the current shell, so everthing you defined in your script stays in effect:
for example, if you defined a variable JAZZ=great in your script, then
$ propogate.ksh
$ echo $JAZZ

$
but:
$ . propogate.ksh
$ echo $JAZZ
great

mrjazz [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top