LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 07-07-2009, 08:26 PM   #1
ajaypitroda
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
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 69
Why not something like this?
Code:
#!/bin/bash

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

array=(one two three)

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

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


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
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 06:18 PM.

Main Menu
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