The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to pass C array as input to Shell script arunkumar_mca High Level Programming 1 04-30-2009 10:25 AM
How to pass array as an arguement ? rajavu UNIX for Dummies Questions & Answers 16 01-16-2009 01:33 AM
How to pass ksh array to oracle kiranlalka Shell Programming and Scripting 1 12-05-2008 09:27 AM
How To Pass an Array Variable msb65 UNIX for Dummies Questions & Answers 9 09-04-2008 01:48 PM
Can we pass array with call by value in function ranjithpr Shell Programming and Scripting 1 12-26-2007 12:22 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-25-2009
little_wonder little_wonder is offline
Registered User
  
 

Join Date: May 2009
Posts: 26
Thumbs up 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...

  #2 (permalink)  
Old 05-26-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
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 (permalink)  
Old 05-26-2009
little_wonder little_wonder is offline
Registered User
  
 

Join Date: May 2009
Posts: 26
Thumbs up

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.
  #4 (permalink)  
Old 05-26-2009
colemar colemar is offline
Registered User
  
 

Join Date: Apr 2009
Location: Trento, Italy
Posts: 116
Code:
result="$(small.sh ${arrayname[*]})"
result="$(small.sh ${arrayname[@]})"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0