LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-10-2011, 04:53 AM   #1
santhosh_cv
LQ Newbie
 
Registered: Sep 2011
Posts: 14

Rep: Reputation: Disabled
Pass 2 arrays to a BASH script


Need to pass two arrays to a BASH script.

eg: sample.sh is the script which does some processing and which accepts 2 arrays. Could we call sample.sh as

sample.sh "a b c d" "1 2 3 4"

Question : How to read the input arguments onto two separate arrays inside sample.sh script.

thanks in advance.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-10-2011, 05:10 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Code:
array1=( $1 )
array2=( $2 )
Reference: here.
 
3 members found this post helpful.
Old 11-10-2011, 05:22 AM   #3
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 208Reputation: 208Reputation: 208
what catkin said.

Last edited by jhwilliams; 11-10-2011 at 05:24 AM. Reason: catkin's answer is more sensible
 
Old 11-10-2011, 06:23 AM   #4
santhosh_cv
LQ Newbie
 
Registered: Sep 2011
Posts: 14

Original Poster
Rep: Reputation: Disabled
catkin,

Thanks for the reply and it works.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to deal with bash[$style] arrays in a POSIX compliant script? GrapefruiTgirl Programming 6 12-16-2009 11:24 AM
How to pass a c variable to a bash script? daYz Programming 3 09-28-2007 09:30 AM
how to pass a keystroke to a bash script? minike Programming 5 01-21-2007 12:42 PM
bash script help (arrays and strings from files) nkoplm Programming 14 12-02-2005 10:50 AM
bash script - variables & arrays question rblampain Linux - Software 4 09-25-2004 10:57 AM


All times are GMT -5. The time now is 05:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration