Go Job Hunting at the LQ Job Marketplace
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-07-2009, 08:26 PM   #1
LQ Newbie
Registered: Jul 2009
Posts: 2

Rep: Reputation: 0
passing array and variable to function in bash script

Hi Guys,

I need to pass an array variable and a string variable to function. So far I am able to pass array to function, but cant figure out how to pass along with array.
any help appreciated. thx in advance
Old 07-07-2009, 09:06 PM   #2
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 71
Why not something like this?

	string=$1 && shift
	echo "string is $string"
	echo "array is ${array[@]}"

array=(one two three)

foo bar ${array[@]}
Old 07-07-2009, 11:10 PM   #3
LQ Newbie
Registered: Jul 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thx buddy, I spent last three days trying to figure this out.


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
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
create a global associative array variable inside a function of a bash script konsolebox Programming 3 07-14-2009 06:08 AM
ARGGGH! Passing array of structs to function in C. CoderMan Programming 5 02-05-2009 10:44 PM
Perl question: Passing variable into function rjcrews Programming 0 10-06-2006 09:24 AM
Bash Script Passing variable to Function nutthick Programming 2 02-02-2005 05:15 AM

All times are GMT -5. The time now is 02:31 AM.

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