Sponsored Content
Top Forums Shell Programming and Scripting How to pass and read an array in ksh shell script function.? Post 303039839 by mohtashims on Wednesday 16th of October 2019 08:01:06 AM
Old 10-16-2019
How to pass and read an array in ksh shell script function.?

I'm able to read & print an array in varaible called "filelist"

I need to pass this array variable to a function called verify() and then read and loop through the passed array inside the function.

Unfortunately it does not print the entire array from inside the funstion's loop.

Code:
#/bin/ksh
set -A filelist val1 val2 val3
set -A FList

verifyfiles()
{
FList="${1[@]}"

for sym in "${FList[@]}"
do
echo "Array in FUNCTION Contains:"
    echo "$sym"
done
}

verifyfiles $filelist

 

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
Class::Gomor::Array(3pm)				User Contributed Perl Documentation				  Class::Gomor::Array(3pm)

NAME
Class::Gomor::Array - class and object builder, array version SYNPOSIS
# Create a base class in BaseClass.pm package My::BaseClass; require Class::Gomor::Array; our @ISA = qw(Class::Gomor::Array); our @AS = qw(attribute1 attribute2); our @AA = qw(attribute3 attribute4); our @AO = qw(other); # You should initialize yourself array attributes sub new { shift->SUPER::new(attribute3 => [], attribute4 => [], @_) } # Create indices and accessors My::BaseClass->cgBuildIndices; My::BaseClass->cgBuildAccessorsScalar(@AS); My::BaseClass->cgBuildAccessorsArray(@AA); sub other { my $self = shift; @_ ? $self->[$self->cgGetIndice('other')] = [ split(/ /, shift) ] : @{$self->[$self->cgGetIndice('other')]}; } 1; # Create a subclass in SubClass.pm package My::SubClass; require My::BaseClass; our @ISA = qw(My::BaseClass); our @AS = qw(subclassAttribute); My::SubClass->cgBuildIndices; My::SubClass->cgBuildAccessorsScalar(@AS); sub new { shift->SUPER::new( attribute1 => 'val1', attribute2 => 'val2', attribute3 => [ 'val3', ], attribute4 => [ 'val4', ], other => [ 'none', ], subclassAttribute => 'subVal', ); } 1; # A program using those classes my $new = My::SubClass->new; my $val1 = $new->attribute1; my @values3 = $new->attribute3; my @otherOld = $new->other; $new->other("str1 str2 str3"); my @otherNew = $new->other; print "@otherNew "; $new->attribute2('newValue'); $new->attribute4([ 'newVal1', 'newVal2', ]); DESCRIPTION
This class is a subclass from Class::Gomor. It implements objects as array references, and inherits methods from Class::Gomor. GLOBAL VARIABLES
See Class::Gomor. METHODS
new (hash) Object constructor. This is where user passed attributes (hash argument) are checked against valid attributes (gathered by cgGetAttributes method). Valid attributes are those that exists (doh!), and have not an undef value. The default is to check this, you can avoid it by setting $NoCheck global variable (see perldoc Class::Gomor). cgBuildIndices You MUST call this method one time at the beginning of your classes, and all subclasses (even if you do not add new attributes). It will build the matching between object attributes and their indices inside the array object. Global variables will be created in your class, with the following format: $__attributeName. cgBuildAccessorsScalar (array ref) cgBuildAccessorsArray (array ref) See Class::Gomor. cgGetIndice (scalar) Returns the array indice of specified attribute passed as a parameter. You can use it in your programs to avoid calling directly the global variable giving indice information concerning requesting object, thus avoiding using `no strict 'vars';'. This method is usually used when you build your own accessors (those using attributes defined in @AO). cgClone [ (scalar) ] You can clone one of your objects by calling this method. An optional parameter may be used to create multiple clones. Cloning will occure only on the first level attributes, that is, if you have attributes containing other objects, they will not be cloned. cgFullClone [ (scalar) ] This method is the same as cgClone, but will clone all attributes recursively, but only if they are subclassed from Class::Gomor. So, objects created with other modules than Class::Gomor::Array or Class::Gomor::Hash will not be cloned. Another thing to note, there is no catch for cycling references (when you link two objects with each others). You have been warned. cgDumper Will return a string as with Data::Dumper Dumper method. This is useful for debugging purposes, because an arrayref object does not include attributes names. SEE ALSO
Class::Gomor AUTHOR
Patrice <GomoR> Auffret COPYRIGHT AND LICENSE
Copyright (c) 2004-2009, Patrice <GomoR> Auffret You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive. perl v5.10.1 2009-05-23 Class::Gomor::Array(3pm)
All times are GMT -4. The time now is 11:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy