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
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 08:39 AM
Simple to you not simple to me pattern matchin help aleks001 Shell Programming and Scripting 0 07-22-2007 07:06 PM
Simple C question... Hopefully it's simple Xeed High Level Programming 6 12-15-2006 11:29 AM
Function within function (Recurance) chassis UNIX for Dummies Questions & Answers 2 09-19-2006 06:32 AM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 10:03 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-05-2001
Registered User
 

Join Date: Jul 2001
Location: US
Posts: 25
Question simple function

hi all,

I am new to Shell Programming. I had a simple function here:

function xyz {
print "test"
}

I save the file as "abc" and give X to all. After I type abc from the terminal, I don't get the "test" as output. Am I missing anything?

Thank you for your input in advance.
Forum Sponsor
  #2  
Old 10-05-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Is that all ther is to your shell script?

You have to "call" the function...

#!/bin/ksh

function xyz {
print "test"
}

xyz

exit 0
  #3  
Old 10-05-2001
Registered User
 

Join Date: Jul 2001
Location: US
Posts: 25
Thanks rwb1959.

It works. I am reading the chapter about Shell Programming of "Learning the Korn Shell" from O'Reilly. I am trying out e.gs. However, they don't have the two lines:

xyz
exit 0

Although the problem is solved, I am wondering how come they would not have that. Is there any other way to "call" the function? I would appreciate it if you would let me know.
  #4  
Old 10-05-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Typically, as in many "Learning" books, they are building
on past examples and it saves alot of paper if you don't keep
printing the "whole" program/script over and over. So...
you must call functions by name for them to be executed.

Just FYI, the "exit 0" statement is not necessary.
I just like including an exit code in case this shell script
is executed by some other shell script or program. This way,
you can determine the success or failure of the script by
its' exit code. For instance...

exit 0 - All is well
exit 255 - Huston... we've had a problem


The actual values are up to you but normally a "0" exit
code says everything is AOK.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:47 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