Sponsored Content
Full Discussion: ksh functions
Top Forums Shell Programming and Scripting ksh functions Post 302125638 by scriptingmani on Friday 6th of July 2007 06:22:40 AM
Old 07-06-2007
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
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to exit the KSH functions

Hi I am having the script which contains more functions. I want to exit the function if any failure. I tried with exit - the session itself is getting logged out. How can i fix this issue? (11 Replies)
Discussion started by: sharif
11 Replies

2. Shell Programming and Scripting

KSH Functions String return

Hy everybody I'm trying to write a function like function(){ final=$1 return $final } but I get following error: "return: bad non-numeric arg ''" what shall I do? Isn't it possible to return strings?:confused: thanks lucae (2 Replies)
Discussion started by: lucae
2 Replies

3. Shell Programming and Scripting

functions

I have korn shells where I want to create a function passing $1 to a function , determine my $STAT_ENV value, set the paths and return the paths for STATSH,STATPRM,STATSQR,STATSQL,STATCTL TO BE USED IN THE UNIX SCRIPT THE CALLED THE fucnction in the first place. Can someone tell me the best... (2 Replies)
Discussion started by: TimHortons
2 Replies

4. Shell Programming and Scripting

Passing array to functions in ksh script

Let me know if there is a way to pass array to a funtion in ksh script. function isPresent { typeset member member=$1 dbList=$2 echo '$1:' $1 echo '$2' $dbList The array will be at the second position....something like this isPresent 12 <array> if then echo... (3 Replies)
Discussion started by: prasperl
3 Replies

5. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

6. UNIX for Dummies Questions & Answers

Help with functions

Hi, I am exploring with defining functions in my BASH shell scripts. However, I am bit confused about how to pass parameters to my functions. I was under the impression that you must do something like the following: Define a function called "sample_function": function sample_function {... (3 Replies)
Discussion started by: msb65
3 Replies

7. UNIX for Dummies Questions & Answers

== vs -eq and functions

Hey I have a question.... what is the difference between using == vs -eq when testing in WHILE loops. I use the following test that only worked with == signs.... if why do i need == and not -eq? 2. I need to re-use some code in a couple places in this script. is functions my best... (5 Replies)
Discussion started by: danieldcc
5 Replies

8. Programming

Functions

Hi All, Can any one help me. I am calling in a function2 with string as parameter from function1, the function1 gives 3 values. how i get the 3 values from funciton2 to function1. i have to give a return or something. thanks in advance. (2 Replies)
Discussion started by: uday.sena.m
2 Replies

9. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

10. Shell Programming and Scripting

ksh While Loop - passing variables to functions

I'm reading a text file using a while loop but when I call a function from within this loop it exits that same iteration … even though there are many more lines in the file to be read. I thought it was something to do with the IFS setting but it appears that a function call (when run... (3 Replies)
Discussion started by: user052009
3 Replies
CALL_USER_FUNC(3)							 1							 CALL_USER_FUNC(3)

call_user_func - Call the callback given by the first parameter

SYNOPSIS
mixed call_user_func (callable $callback, [mixed $parameter], [mixed $...]) DESCRIPTION
Calls the $callback given by the first parameter and passes the remaining parameters as arguments. PARAMETERS
o $callback - The callable to be called. o $parameter - Zero or more parameters to be passed to the callback. Note Note that the parameters for call_user_func(3) are not passed by reference. Example #1 call_user_func(3) example and references <?php error_reporting(E_ALL); function increment(&$var) { $var++; } $a = 0; call_user_func('increment', $a); echo $a." "; // You can use this instead call_user_func_array('increment', array(&$a)); echo $a." "; ?> The above example will output: 0 1 RETURN VALUES
Returns the return value of the callback, or FALSE on error. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | The interpretation of object oriented keywords | | | like parent and self has changed. Previously, | | | calling them using the double colon syntax would | | | emit an E_STRICT warning because they were inter- | | | preted as static. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #2 call_user_func(3) example <?php function barber($type) { echo "You wanted a $type haircut, no problem "; } call_user_func('barber', "mushroom"); call_user_func('barber', "shave"); ?> The above example will output: You wanted a mushroom haircut, no problem You wanted a shave haircut, no problem Example #3 call_user_func(3) using namespace name <?php namespace Foobar; class Foo { static public function test() { print "Hello world! "; } } call_user_func(__NAMESPACE__ .'Foo::test'); // As of PHP 5.3.0 call_user_func(array(__NAMESPACE__ .'Foo', 'test')); // As of PHP 5.3.0 ?> The above example will output: Hello world! Hello world! Example #4 Using a class method with call_user_func(3) <?php class myclass { static function say_hello() { echo "Hello! "; } } $classname = "myclass"; call_user_func(array($classname, 'say_hello')); call_user_func($classname .'::say_hello'); // As of 5.2.3 $myobject = new myclass(); call_user_func(array($myobject, 'say_hello')); ?> The above example will output: Hello! Hello! Hello! Example #5 Using lambda function with call_user_func(3) <?php call_user_func(function($arg) { print "[$arg] "; }, 'test'); /* As of PHP 5.3.0 */ ?> The above example will output: [test] NOTES
Note Callbacks registered with functions such as call_user_func(3) and call_user_func_array(3) will not be called if there is an uncaught exception thrown in a previous callback. SEE ALSO
call_user_func_array(3), is_callable(3), information about the callback type, ReflectionFunction::invoke, ReflectionMethod::invoke. PHP Documentation Group CALL_USER_FUNC(3)
All times are GMT -4. The time now is 01:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy