The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need explanation of script vishalpatel03 Shell Programming and Scripting 0 11-25-2007 05:55 PM
Different behaviour of this program royalibrahim High Level Programming 7 10-20-2007 07:07 PM
Explanation of running this script sendhilmani Shell Programming and Scripting 2 03-21-2006 03:07 AM
Can some 1 explain why this behaviour helpmenow High Level Programming 2 12-18-2005 03:28 PM
Script explanation sickboy Shell Programming and Scripting 8 06-13-2005 02:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-23-2001
xiamin xiamin is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 64
any explanation for thsi shell script behaviour

hello

whats the difference between excuting a shell script as

a)sh myscript.sh
b). ./myscript.sh

i noticed that my shell script works fine when i run it as . ./myscript
.sh but fails when i run it as sh myscript.sh could anybody explain why.

the shell script is very simple

#!/bin/sh
startx

regards
Hrishy
  #2 (permalink)  
Old 10-23-2001
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Try using the full path to the startx script... the . ./script will work because your path is set up, but ./script or sh script may not if it's not in the default path...
  #3 (permalink)  
Old 10-23-2001
xiamin xiamin is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 64
Hmm Livin free

Both of the scripts

a)sh myscript.sh
b). ./myscript.sh

are in my path .but i dont undersatnd the difference in behaviour

regards
Hrishy
  #4 (permalink)  
Old 10-23-2001
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,100
In one case a subshell runs the script, in the second case the login shell runs the script.
  #5 (permalink)  
Old 11-08-2001
Rado1x Rado1x is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 35
I'm not sure. I think that in the both cases is spawned child shell.
  #6 (permalink)  
Old 11-08-2001
doeboy's Avatar
doeboy doeboy is offline
Registered User
  
 

Join Date: Oct 2001
Location: Here
Posts: 137
I would have to disagree with that statement that both cases spawn a child shell.

Perderabo is correct.
  #7 (permalink)  
Old 11-08-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Agreed. Perderabo is correct.

...from the bash man page regarding dot "." notation or
"source"ing...

. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the cur-
rent shell environment and return the exit status
of the last command executed from filename. If
filename does not contain a slash, pathnames in
PATH are used to find the directory containing
filename. The file searched for in PATH need not
be executable. The current directory is searched
if no file is found in PATH. If any arguments are
supplied, they become the positional parameters
when file is executed. Otherwise the positional
parameters are unchanged. The return status is the
status of the last command exited within the script
(0 if no commands are executed), and false if file-
name is not found.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0