LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 03: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, 04:10 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

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

Rep: Reputation: 211Reputation: 211Reputation: 211
what catkin said.

Last edited by jhwilliams; 11-10-2011 at 04:24 AM. Reason: catkin's answer is more sensible
 
Old 11-10-2011, 05: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



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 8 01-02-2015 11:17 PM
How to pass a c variable to a bash script? daYz Programming 3 09-28-2007 08:30 AM
how to pass a keystroke to a bash script? minike Programming 5 01-21-2007 11:42 AM
bash script help (arrays and strings from files) nkoplm Programming 14 12-02-2005 09:50 AM
bash script - variables & arrays question rblampain Linux - Software 4 09-25-2004 09:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:55 PM.

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
Open Source Consulting | Domain Registration