LinuxQuestions.org
Review your favorite Linux distribution.
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 03-12-2009, 11:48 AM   #1
Raht
LQ Newbie
 
Registered: Nov 2008
Posts: 2

Rep: Reputation: 0
Initializing arrays in bash


Hello there,

I am fairly sure this one is a result of some stupid mistake i overlooked, but i really ran out of ideas...

I'm making script for automated compiling of one program which would output builds optimized for many architectures. For clearancy, I do each build in it's own catalogue and list of builds with their respective catalogues would be stored as array.

I'm using this guide as reference. It describes making array as naming a variable with additional brackets denoting it's position in array.

In my code, it looks exactly like this:
Code:
mtune[1]="build/mtune/athlon"
mtune[2]="build/mtune/athlon-4"
mtune[3]="build/mtune/athlon-mp"
mtune[4]="build/mtune/athlon-tbird"
mtune[5]="build/mtune/athlon-xp"
mtune[6]="build/mtune/c3"
mtune[7]="build/mtune/c3-2"
mtune[8]="build/mtune/core2"
mtune[9]="build/mtune/i386"
mtune[10]="build/mtune/i486"
mtune[11]="build/mtune/i586"
mtune[12]="build/mtune/i686"
mtune[13]="build/mtune/k6"
mtune[14]="build/mtune/k6-2"
mtune[15]="build/mtune/k6-3"
mtune[16]="build/mtune/k8"
mtune[17]="build/mtune/opteron"
mtune[18]="build/mtune/pentium"
mtune[19]="build/mtune/pentium-m"
mtune[20]="build/mtune/pentium-mmx"
mtune[21]="build/mtune/pentium2"
mtune[22]="build/mtune/pentium3"
mtune[23]="build/mtune/pentium4"
mtune[24]="build/mtune/pentiumpro"
mtune[25]="build/mtune/prescott"
But upon invoking $mtune or any $mtune[x] variable, output is blank, like the variable(s) were never initialized. What am I doing wrong?
 
Old 03-12-2009, 12:33 PM   #2
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 231Reputation: 231Reputation: 231
Maybe you should post your script as it's hard to tell what you are doing. This may give you some insight :
Code:
mtune[1]="build/mtune/athlon"
mtune[2]="build/mtune/athlon-4"
mtune[3]="build/mtune/athlon-mp"
mtune[4]="build/mtune/athlon-tbird"
mtune[5]="build/mtune/athlon-xp"
mtune[6]="build/mtune/c3"
mtune[7]="build/mtune/c3-2"
mtune[8]="build/mtune/core2"
mtune[9]="build/mtune/i386"
mtune[10]="build/mtune/i486"
mtune[11]="build/mtune/i586"
mtune[12]="build/mtune/i686"
mtune[13]="build/mtune/k6"
mtune[14]="build/mtune/k6-2"
mtune[15]="build/mtune/k6-3"
mtune[16]="build/mtune/k8"
mtune[17]="build/mtune/opteron"
mtune[18]="build/mtune/pentium"
mtune[19]="build/mtune/pentium-m"
mtune[20]="build/mtune/pentium-mmx"
mtune[21]="build/mtune/pentium2"
mtune[22]="build/mtune/pentium3"
mtune[23]="build/mtune/pentium4"
mtune[24]="build/mtune/pentiumpro"
mtune[25]="build/mtune/prescott"
for ((member=1;member<=${#mtune[*]};member++)); do
	echo Member $member contains ${mtune[$member]}
done
 
  


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
Bash Arrays Simon256 Programming 2 02-17-2009 01:39 PM
LXer: Bash Arrays LXer Syndicated Linux News 0 06-20-2008 06:20 PM
[bash] How do I nest for arrays? blckleprd Programming 3 06-05-2008 10:49 PM
initializing arrays of structures in c dreamgoat Programming 5 09-27-2004 02:02 AM
bash for statement with 2 arrays? Noerr Linux - General 10 05-27-2002 12:58 PM

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

All times are GMT -5. The time now is 03:52 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration