Sponsored Content
Top Forums Shell Programming and Scripting How to pass and read an array in ksh shell script function.? Post 303039876 by mohtashims on Thursday 17th of October 2019 12:34:57 AM
Old 10-17-2019
Quote:
Originally Posted by Corona688
If your values will never contain spaces, you can "pass" arrays as strings "val1 val2 val3" and split them back inside the function, like this:

Code:
#!/bin/ksh

set -A filelist val1 val2 val3
set -A otherlist q1 q2 q3

verifyfiles() {
        set -A Flist $1
        set -A Qlist $2
        echo "flist[0]=${Flist[0]}"
        echo "qlist[0]=${Qlist[0]}"
}

verifyfiles "${filelist[*]}" "${otherlist[*]}"

Thank you .... Works Perfect @Corona @RudiC.
This User Gave Thanks to mohtashims For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass arguments to a function in a shell script?

Hi, I have two shell variables $t1 and $t2 which I need to pass to a function in a shell script. The function will do some computation with those two variables and echo the resultant. But I do not know how to pass teh arguments. The function written is f1() {...... ........ } What should... (3 Replies)
Discussion started by: preetikate
3 Replies

2. Shell Programming and Scripting

How to read values that are passed to the shell function in ksh.

In ksh shell, There is a function f1. function f1 { How to read here?? .... .... } I am passing values to fuunction f1 as f1 "A" "B" Please tell me how to read the passed values in function f1. Advance Thanks & Regards Prashant (2 Replies)
Discussion started by: prashant43
2 Replies

3. 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

4. Programming

How to pass C array as input to Shell script

Hi, In the below C code , i want to pass the array to a unix shel script. my script should called as ex myscript 1,2,3 #include <stdio.h> int main() { int a={1,2,3}; } Thanks, Arun (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

5. Shell Programming and Scripting

What is the maximum number of parameter we can pass to a shell script function?

what is the maximum number of parameter we can pass to a shell script function (8 Replies)
Discussion started by: alokjyotibal
8 Replies

6. Shell Programming and Scripting

How to pass parameter to User defined function in shell script?

Hello, Can anyone guide me tin passing parameters into user defined function of shell script (KSH). Here is my code, InsertRecord() { DB_TBL=$(sqlplus $USERID/$PASSWORD@$DATABASE << EOF set head off set feed off set serveroutput on INSERT INTO TBL1 ( OLD_VAL, NEW_VAL, ... (7 Replies)
Discussion started by: Poonamol
7 Replies

7. Shell Programming and Scripting

How to pass an array to a function in shell script.?

hi, I have a array say SAP_ARRAY="s1.txt" SAP_ARRAY="s2.txt" how can i pass this full array to a function. here is the sample code i am using.. CHECK_NO_FILES() { FARRAY=$1 echo "FARRAY = $FARRAY" echo "FARRAY = $FARRAY" ............... (5 Replies)
Discussion started by: Little
5 Replies

8. 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

9. Shell Programming and Scripting

Pass C shell array to another C shell script(csh) and shell(sh)

Dear Friends, Please help me on this my script name is send.csh In this i have written the statement like this set args = ( city state country price ) I want to pass this array to another c shell called receiver.csh. and i want to use it in this c shell or how to pass to... (2 Replies)
Discussion started by: SA_Palani
2 Replies

10. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies
STREAM_SELECT(3)							 1							  STREAM_SELECT(3)

stream_select - Runs the equivalent of the select() system call on the given arrays of streams with a timeout specified by tv_sec and tv_usec

SYNOPSIS
int stream_select (array &$read, array &$write, array &$except, int $tv_sec, [int $tv_usec]) DESCRIPTION
The stream_select(3) function accepts arrays of streams and waits for them to change status. Its operation is equivalent to that of the socket_select(3) function except in that it acts on streams. PARAMETERS
o $read - The streams listed in the $read array will be watched to see if characters become available for reading (more precisely, to see if a read will not block - in particular, a stream resource is also ready on end-of-file, in which case an fread(3) will return a zero length string). o $write - The streams listed in the $write array will be watched to see if a write will not block. o $except - The streams listed in the $except array will be watched for high priority exceptional ("out-of-band") data arriving. Note When stream_select(3) returns, the arrays $read, $write and $except are modified to indicate which stream resource(s) actu- ally changed status. You do not need to pass every array to stream_select(3). You can leave it out and use an empty array or NULL instead. Also do not forget that those arrays are passed by reference and will be modified after stream_select(3) returns. o $tv_sec - The $tv_sec and $tv_usec together form the timeout parameter, $tv_sec specifies the number of seconds while $tv_usec the number of microseconds. The $timeout is an upper bound on the amount of time that stream_select(3) will wait before it returns. If $tv_sec and $tv_usec are both set to 0, stream_select(3) will not wait for data - instead it will return immediately, indicating the current status of the streams. If $tv_sec is NULLstream_select(3) can block indefinitely, returning only when an event on one of the watched streams occurs (or if a signal interrupts the system call). Warning Using a timeout value of 0 allows you to instantaneously poll the status of the streams, however, it is NOT a good idea to use a 0 timeout value in a loop as it will cause your script to consume too much CPU time. It is much better to specify a timeout value of a few seconds, although if you need to be checking and running other code concurrently, using a timeout value of at least 200000 microseconds will help reduce the CPU usage of your script. Remember that the timeout value is the maximum time that will elapse; stream_select(3) will return as soon as the requested streams are ready for use. o $tv_usec - See $tv_sec description. RETURN VALUES
On success stream_select(3) returns the number of stream resources contained in the modified arrays, which may be zero if the timeout expires before anything interesting happens. On error FALSE is returned and a warning raised (this can happen if the system call is inter- rupted by an incoming signal). EXAMPLES
Example #1 stream_select(3) Example This example checks to see if data has arrived for reading on either $stream1 or $stream2. Since the timeout value is 0 it will return immediately: <?php /* Prepare the read array */ $read = array($stream1, $stream2); $write = NULL; $except = NULL; if (false === ($num_changed_streams = stream_select($read, $write, $except, 0))) { /* Error handling */ } elseif ($num_changed_streams > 0) { /* At least on one of the streams something interesting happened */ } ?> NOTES
Note Due to a limitation in the current Zend Engine it is not possible to pass a constant modifier like NULL directly as a parameter to a function which expects this parameter to be passed by reference. Instead use a temporary variable or an expression with the left- most member being a temporary variable: <?php $e = NULL; stream_select($r, $w, $e, 0); ?> Note Be sure to use the === operator when checking for an error. Since the stream_select(3) may return 0 the comparison with == would evaluate to TRUE: <?php $e = NULL; if (false === stream_select($r, $w, $e, 0)) { echo "stream_select() failed "; } ?> Note If you read/write to a stream returned in the arrays be aware that they do not necessarily read/write the full amount of data you have requested. Be prepared to even only be able to read/write a single byte. Note Some streams (like zlib) cannot be selected by this function. Note Windows compatibility: stream_select(3) used on a pipe returned from proc_open(3) may cause data loss under Windows 98. Use of stream_select(3) on file descriptors returned by proc_open(3) will fail and return FALSE under Windows. SEE ALSO
stream_set_blocking(3). PHP Documentation Group STREAM_SELECT(3)
All times are GMT -4. The time now is 12:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy