The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Background execution of a script Cameron Shell Programming and Scripting 2 10-03-2007 02:50 AM
error during the execution of script surjyap Shell Programming and Scripting 1 08-24-2007 05:10 PM
Pb with script execution and variables Cecile AIX 1 09-15-2006 06:54 AM
Script execution information manthasirisha Shell Programming and Scripting 12 07-07-2006 05:54 AM
execution of shell script malaymaru Shell Programming and Scripting 5 06-13-2005 06:49 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-14-2006
Registered User
 

Join Date: Aug 2006
Location: Lyon France
Posts: 12
pb with script execution

Hello,

Can somebody tell me the differnce between a call of a ksh with the dot :

>. script.ksh

and the call without the dot:

>script.ksh

In my script I have writen a test for the number of parameters:
if [ $# -ne 0 ]
then echo 'Usage : '$0
exit 1
fi

as my script doesn't need any parameter

if I call like this:
>. script.ksh
$# =
$0 = -ksh
which is wrong
I can't do a correct test of my parameters, but if I remove the parameter test I can give value to variables, and these variables are known and have a value in my parent shell and can be used by other scripts

If I call like this:
>script.ksh
$# = 0
$0 = script.ksh
which is OK, but I want to export variables that must be used in other script and my variables remains unknown in my parent shell
but it seems that I can execute other script that can see the variables....

I don't understand anything....

see you
Cécile
Reply With Quote
Forum Sponsor
  #2  
Old 09-14-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
When you run a script as ". ./scriptname", the script executes in the context of the current shell. All your shell variables (such as $0, $#, etc) will also be those of the current shell. So showing $0 to be -ksh is what should happen.

Since the script that you are using is basically to setup env. variables, don't check for things like $0, just export your variables and be done with it.
Reply With Quote
  #3  
Old 09-14-2006
Registered User
 

Join Date: Aug 2006
Location: Lyon France
Posts: 12
pb with script execution

Thank you for your answer.

I understand a little bit more.

If a call with the dot I stay in the parent shell ?
In fact I don't really execute the script but I read it??
Do I execute another shell when I call a script with the dot ?

You 're right I don't need to check parameters here.

Ok, it works when I call like that :

. Script1.ksh

. Script2.ksh
Reply With Quote
  #4  
Old 09-14-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 989
Quote:
Originally Posted by Cecile
If a call with the dot I stay in the parent shell ?
In fact I don't really execute the script but I read it??
Absolutely correct. As far as I know, sourced scripts don't even need to be set executable.
Quote:
Do I execute another shell when I call a script with the dot?
Nope, it runs in the existing one. They call it 'sourcing' but a better name might be 'include' or 'import'.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0