LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 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: 78
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



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

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

All times are GMT -5. The time now is 08:12 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
Open Source Consulting | Domain Registration