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
Need help in checking the date and looking for a keyword in a script tatchel Shell Programming and Scripting 0 04-21-2008 05:46 PM
how to search a keyword within a file using a for loop lucho_1 Shell Programming and Scripting 6 03-10-2008 11:57 AM
keyword searching of documents Miles OS X (Apple) 1 02-25-2008 03:38 PM
Far Keyword svh High Level Programming 2 02-07-2006 09:16 PM
Keyword in perl sarwan Shell Programming and Scripting 1 01-17-2006 01:35 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-25-2008
Registered User
 

Join Date: Feb 2008
Location: SFO, Ca, US
Posts: 8
Using $0 and 'Function' Keyword

Hi all,

I had a query on the usage of $0 in shells. I would appreciate any assistance in this.

We moved from a sun solaris server to a linux server. I ran 2 different pieces on these servers and in one case, the outputs didnt change and in the other case, the outputs were different. The 2 pieces involved defining functions differently.

Case #1
----------------------------------
#!/bin/ksh

echo "Value of $0 outside"

function callme2
{
echo "Value of $0 inside"
}

callme2
----------------------------------

Case #2
----------------------------------
#!/bin/ksh

echo "Value of $0 outside"

callme2()
{
echo "Value of $0 inside"
}

callme2
----------------------------------

Sun solaris output was the same in both cases, as given below.

Value of test.ksh outside
Value of test.ksh inside

But, the linux server gave different outputs.

case #1 output

Value of .//test.ksh outside
Value of callme2 inside

case #2 output

Value of .//test.ksh outside
Value of .//test.ksh inside

Can someone assist me in understanding why these differences exist inspite of the shell remaining the same and also what can be done to prevent this from occurring.

Thank you very much for your time...!!
Reply With Quote
Forum Sponsor
  #2  
Old 08-26-2008
vbe vbe is offline
Moderator
 

Join Date: Sep 2005
Location: Switzerland
Posts: 775
It has to do with the shell behaviour...
Your first case (solaris...) is the what you would expect from a bourne shell...

The second is what most ksh implementation would give...

The question is when you call callme2, is it or not a $0


All the best
Reply With Quote
  #3  
Old 08-26-2008
Registered User
 

Join Date: Feb 2008
Location: SFO, Ca, US
Posts: 8
Thanks!

But, doesn't the command '#!/bin/ksh' invoke the korn shell? This was one of the reasons I was so surprised when the shell was giving different results on both servers.
Reply With Quote
  #4  
Old 08-26-2008
vbe vbe is offline
Moderator
 

Join Date: Sep 2005
Location: Switzerland
Posts: 775
but /bin/ksh wasnt the favorite shell under solaris (but is it now?)
You try your script on a HP-UX and Im sure you will have something like:
Value of test.ksh outside
Value of callme2 inside
and if you used sh on HP-UX you would have the solaris output, unfortunately Im at home now and cant confirm by testing on different platforms.. but Im confident about HPUX...
As said I believe it being more philosophical:
When you call callme2, you agree its like executing a module no? So is it $0?
It depends on your understanding I suppose...
That is maybe also why many courses are given in bourne shell, question of compatibility...
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 09:59 PM.


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