How to pass an array as arg to a script..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass an array as arg to a script..
# 1  
Old 05-26-2009
MySQL How to pass an array as arg to a script..

Hi,

Please guide to pass an array as a arg to a script...


for example,

I have a script small.sh to find the small no of given arg as below...

#! /bin/sh

# this script is for finding the small number

set -A arr_no_updates

small=$1
i=1
for arr in $@
do
if [ $arr -ne 0 ]
then
if [ $arr -le small ]
then
small=$arr
fi
fi

i=$(($i+1))
done
echo $small


Now i like to use this script for muliple times in another script called secondscript.sh


please help me on the following
1.how to call the small.sh
2.how to pass the array as arg
3.how to get the result


I tried for the non array codes, i could get the perfect result with the below lines..

chmod 777 small.sh
./small.sh 10 20 30

please help me hw to arg a array.. Thankyou all in advance...

Smilie
# 2  
Old 05-26-2009
I still don't understand why you wanna store arg into array internally ita stored in array only by using for loop you can access it one by one
and inside for loop why are you incrementing i??
# 3  
Old 05-26-2009
MySQL

Hi vidyadhar85,

Sorry if my question confuse you..
actually i want to pass an array as argument..
please find the script named small.sh.. This script is to find small no from a list..

i want to call this small.sh in another script secondscript.sh, where as i wish to pass a array as argument..

for ex, if i have 3 arrays in secondscript.sh. i want to use small.sh to find the smallest no of each array..

hope the scenario is clear now. Smilie
# 4  
Old 05-26-2009
Code:
result="$(small.sh ${arrayname[*]})"
result="$(small.sh ${arrayname[@]})"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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. #/bin/ksh... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. UNIX for Dummies Questions & Answers

How to pass first array value?

Hi, I am creating filesystem for block device, but I want to pass array value one by one acording to block device count. $tmp1 = block device count 3 $blockdevice = So I want to first pass sdb1 alone in loop, how to take only block device seprately from $blockdevice array. (1 Reply)
Discussion started by: stew
1 Replies

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

4. Shell Programming and Scripting

Pass command line arg to sql file

Hi all, How to pass the command line argument to a sql file Script: #!/bin/ksh if ] ; then test.sql fi My Sql Informix DB: echo "select * from table where col1 = 2234 and col2 = '$3'"|dbaccess ddname But im getting `:' unexpected error (5 Replies)
Discussion started by: Roozo
5 Replies

5. Shell Programming and Scripting

How to pass an array containing file names to a sftp script?

hi, i want to pass an array parameters to a sftp script so that i can transfer each file in the array to the remote server by connecting only once to the sftp remote server. i thought of using a variable that contains list of file names separated by a space and pass the variable to the sftp... (3 Replies)
Discussion started by: Little
3 Replies

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

7. Shell Programming and Scripting

Pass string arg from shell to perl

My shell script generates a bunch of lines of text and passes this text as an argument to a perl script. I'm able to do this, but for some reason newlines don't get recognized in the perl script and so the script just prints actual '\n' instead of carriage returning, otherwise everything gets... (3 Replies)
Discussion started by: stevensw
3 Replies

8. Shell Programming and Scripting

Can we pass an array of strings from a Perl Program to a Shell Script?

Hi Folks, The subject is my question: Can we pass an array of strings from a Perl Program to a Shell Script? Please provide some sample code. Thanks ---------- Post updated at 11:52 PM ---------- Previous update was at 11:43 PM ---------- I got it. Its here:... (0 Replies)
Discussion started by: som.nitk
0 Replies

9. Programming

warning: int format,pid_t arg (arg 2)

I try following code under Solaris10,like follows: int glob = 6; int main(void) { int var; pid_t pid; var = 88; printf("before vfork\n"); if ((pid = vfork()) < 0) { err_sys("vfork error"); } else if (pid == 0) { glob++; var++; _exit(0); } ... (1 Reply)
Discussion started by: konvalo
1 Replies

10. 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
Login or Register to Ask a Question