The UNIX and Linux Forums  

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
Multiple functions amitrajvarma Shell Programming and Scripting 1 11-27-2007 11:21 AM
Use of functions amitrajvarma Shell Programming and Scripting 1 11-23-2007 06:52 AM
functions in Raom Shell Programming and Scripting 6 07-21-2006 04:06 AM
Regarding functions sendhilmani Shell Programming and Scripting 2 03-24-2006 04:40 AM
FTP functions hzambra High Level Programming 3 05-03-2002 02:06 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-06-2007
scriptingmani scriptingmani is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 17
ksh functions

Hi All,

just wanted to ask if functions created in a Korn shell script can be passed parameters and if so what is the syntax for creating a function with parameters?

thanks

Mani
  #2 (permalink)  
Old 07-06-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,763
Yes - example
Code:
myfunction()
{
    echo "$1 $2"
}

myfunction "This is parameter 1"  " Another parameter"
myfunction  32 64
You call the function with a list of parms, inside the function the parms are identified by $n where n is the number of the parameter.
  #3 (permalink)  
Old 07-06-2007
scriptingmani scriptingmani is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 17
thanks for the speedy response

could it also return a single value if i used a return statement i.e. return $x ?
I have tried it but doesn't seem to work.

Mani
  #4 (permalink)  
Old 07-06-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by scriptingmani View Post
thanks for the speedy response

could it also return a single value if i used a return statement i.e. return $x ?
I have tried it but doesn't seem to work.

Mani
Return statement is used to return an exit value from a shell function to the calling script.

To return string use echo statement.
Code:
myfunction()
{
    echo "$1"
}

str=$( myfunction "This is parameter 1"  " Another parameter")
echo $str
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 12:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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