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

Differences in How you run a Script

Status
Not open for further replies.

Edcrosbys

ISP
Apr 26, 1999
112
0
0
US
Why would you run a script with "sh ./scriptname" as opposed to just running it with "./scriptname" or ". ./scriptname"? Could someone point me in the right direction?

Just FYI (I don't think you'll need this, but), I'm running Sun 8 on a V880. And this question was brought about by the latest Oracle security patch, which has you run it via the "sh ./scriptname" method.


Thanks,
Eric
 
Eric,

basically the ./ tells the shell that the script is in the current directory. If the directory is included in your $PATH variable, it shouldn't be necessary to include the ./ Hope this helps.
 
Ken,

Hmmm... Page Not Found... I'll try again later..

As far as the ./ showing that the file is in your current directory I understand. Whats the difference btwn these:

./scriptname . ./scriptname
. ./scriptname sh ./scriptname

I'll definatly check the link out later.

Thanks,
Eric
 
Eric, sorry about that, it seems the paste didn't work too well. The FT228 in the address above should be FT228-3

Hope you get to it this time!
 
Eric,

As you ask, i'll try to explain the differences.

./scriptname

When you use this, the script name must be in the local directory to run

. ./scriptname
. ./scriptname

This both ways, means that you are running the scriptname from located on directory above the local dir.

sh ./scriptname

Finally, this way starts a bourne shell and then it 'll be the shell interpreter to run this scriptname.

I hope it can help you.

Eduardo
 
Eduardo,

Okay, I understand that. Why would you run something in it's own shell interpreter? Thge first line of the script identifies which shell or program to use to interpret the script. So it wouldn't be for that reason. What benefit does a sript having it's own interpreter (sh ./scriptname) give?
 
Actually, the form...
[tt]
. ./scriptname
[/tt]
...is not running a script in the parent directory. The dot-space-script form is to run the commands from that file in the current shell. Otherwise the script is run in a subshell. This would be needed for things like defining variables that you want defined in the current shell, and doing cd's and things like that.

Hope this helps.

 
Just my 2 cents worth - I thing that running sh script simply executes the script as if typen into the the shell. Often used when a script may not have the !#/usr/bin/sh line in it - overrides any shell settings. Also the script file does not need to have the executable bit set - most commonly seen when sourcing starup and shutdown scripts which are simply lists of commands parsed by the rc scripts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top