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 12-31-2007, 11:13 PM   #1
som_kurian
Member
 
Registered: Oct 2007
Posts: 33

Rep: Reputation: 15
Two dimensional array


Is it possible to write a Two dimensional array in bash script..If Yes then can you guys give me an example to do this..I tried one dimensional array.Is it in the similar way
 
Old 01-01-2008, 03:13 AM   #2
jozyba
Member
 
Registered: Sep 2007
Distribution: Debian Etch, Lenny, Lenny/Sid
Posts: 31

Rep: Reputation: 15
No, you can only have one-dimentional arrays in bash, but there's an interesting post from comp.unix.shell by Chris F.A. Johnson on how to emulate a two-dimentional array:
http://www.dbforums.com/archive/index.php/t-364801.html
 
Old 01-01-2008, 03:27 AM   #3
SeRGeiSarov
Member
 
Registered: Jan 2007
Location: Russia, Nizhniy Novgorod Region, Sarov town
Distribution: Mandriva 2007, Fedore Core 6
Posts: 52

Rep: Reputation: 15
May be
Code:
#!/bin/sh
i=5
j=6
for ((k=0;k<$((i*j));k++))
do
  FOO[k]=$k
done

for ((m=0;m<$i;m++))
do
  for ((n=0;n<$j;n++))
  do
    echo ${FOO[$((m*j+n))]}
  done
done
 
  


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
Maximum 4 dimensional array size disruptive Programming 26 02-06-2007 10:51 PM
two dimensional array sorting in C/C++ George2 Programming 10 11-19-2006 08:29 PM
building a three dimensional array in vb6 mrobertson Programming 0 08-18-2005 09:12 AM
Bash 2 dimensional array ldp Linux - General 5 07-29-2005 11:29 AM
3 dimensional array help leeach Programming 11 06-15-2005 10:46 AM

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

All times are GMT -5. The time now is 08:25 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