Sponsored Content
Top Forums Shell Programming and Scripting Generic function which takes an array Post 302835055 by bakunin on Sunday 21st of July 2013 04:07:56 PM
Old 07-21-2013
Quote:
Originally Posted by Don Cragun
I did say in my earlier posting:
Quote:
If you have a 1993 or later version of the Korn shell
While this is absolutely correct there is a somewhat sophisticated trick by which it is possible to do the same in ksh88:

Code:
function caller {
typeset achArray[1]="foo"
typeset achArray[2]="bar"

callee achArray

return 0
}

function callee {
typeset -i iCnt=1

while [ $iCnt -le $(eval print \${#$1[*]}) ] ; do
    print - $(eval print - \${$1[$iCnt]})
done

return 0
}

Just in case it needs mentioning: possibility does not imply advisability. As the code above contradicts encapsulation (callee() uses variables that are silently inherited from caller() ) i wouldn't resort to such methods if there is any other and simpler way to do it. Sometimes, though, you just have no choice other than to be tricky.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. Programming

Function to return an array of integer

Hi all, I am trying to create a function that return an array of integer based on the char parameter pass into the function. I.e. func_a(char * str) { example str is equal to "1,2,3,4" return an array of integers of 1,2,3,4 } Please advise regards dwgi32 (2 Replies)
Discussion started by: dwgi32
2 Replies

2. Shell Programming and Scripting

Can we pass array with call by value in function

I want to pass an array in my function, And my function will be changing the elements of the array in the fuction, but it should not affect the values in my array variable of main function (1 Reply)
Discussion started by: ranjithpr
1 Replies

3. Shell Programming and Scripting

function return array

Hi all I would like to know if there is a way to return an array for a function. As I know function can return all the contents in an array, I want to return an array type. (6 Replies)
Discussion started by: dophine
6 Replies

4. Shell Programming and Scripting

How to pass an array from SHELL to C function

Hi, I have an output generated from a shell script like; 0x41,0xF2,0x59,0xDD,0x86,0xD3,0xEF,0x61,0xF2 How can I pass this value to the C function, as below; int main(int argc, char *argv) { unsigned char hellopdu={above value}; } Regards Elthox (1 Reply)
Discussion started by: elthox
1 Replies

5. Shell Programming and Scripting

[bash] passing array to function

Hi, I'm trying to write a function that reassigns an array to another local array but the method used in reassigning the array reformats the contents of the array which is what I am trying to prevent. The method used to load a file into an array works as expected and the entire array is... (4 Replies)
Discussion started by: ASGR
4 Replies

6. Shell Programming and Scripting

Print Array function

The code below prints outs each array element, but it always says the array length is 1 even though its not. What am i doing wrong? function printArray(){ #here should check if it is an array and that an arg exits echo "Priting array" myarr="${@}" echo... (2 Replies)
Discussion started by: chrisjones
2 Replies

7. Programming

Passing two dimensional array to a function

Hi. I have a problem with passing two dimensional array to a function. First, let me show my code to explain what i am going to do: I have function:void initialize_board(char board);which is supposed to modify content of passed array. I have read here: Question 6.18 how such arrays should be... (3 Replies)
Discussion started by: Shang
3 Replies

8. Solaris

Generic drive in a Sun Storage Array?

With a sun storage array j4200 with a failed drive. It's got 11 other drive right now running seagate's ST314655SSUN146G I'm about to replace that one drive with seagate's ST3146356SS drive. Do anyone see this as a problem to use non-Sun drives in Sun storage array or mixing the two... (9 Replies)
Discussion started by: JT-KGY
9 Replies

9. Shell Programming and Scripting

Pass array to a function and display the array

Hi All I have multiple arrays like below. set -A val1 1 2 4 5 set -A val2 a b c d . . . Now i would like to pass the individual arrays one by one to a function and display/ do some action. Note : I am using ksh Can you please advise any solution... Thanks in advance. (7 Replies)
Discussion started by: Girish19
7 Replies

10. Programming

How to Declare an array of function pointers?

I am attempting to create an array of function pointers. The examples I follow to do this are from: support.microsoft.com/en-us/help/30580/how-to-declare-an-array-of-pointers-to-functions-in-visual-c ... (3 Replies)
Discussion started by: spflanze
3 Replies
TALKD(8)						    BSD System Manager's Manual 						  TALKD(8)

NAME
talkd -- remote user communication server SYNOPSIS
/usr/sbin/in.talkd [-dpq] DESCRIPTION
Talkd is the server that notifies a user that someone else wants to initiate a conversation. It acts a repository of invitations, responding to requests by clients wishing to rendezvous to hold a conversation. In normal operation, a client, the caller, initiates a rendezvous by sending a CTL_MSG to the server of type LOOK_UP (see <protocols/talkd.h>). This causes the server to search its invitation tables to check if an invitation currently exists for the caller (to speak to the callee specified in the message). If the lookup fails, the caller then sends an ANNOUNCE message causing the server to broadcast an announcement on the callee's login ports requesting contact. When the callee responds, the local server uses the recorded invitation to respond with the appropriate rendezvous address and the caller and callee client programs establish a stream connection through which the conversation takes place. OPTIONS
[-d] Debug mode; writes copious logging and debugging information to /var/log/talkd.log. [-p] Packet logging mode; writes copies of malformed packets to /var/log/talkd.packets. This is useful for debugging interoperability prob- lems. [-q] Don't log successful connects. SEE ALSO
talk(1), write(1) HISTORY
The talkd command appeared in 4.3BSD. Linux NetKit (0.17) March 16, 1991 Linux NetKit (0.17)
All times are GMT -4. The time now is 01:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy