LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-01-2008, 12:13 AM   #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, 04: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, 04: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


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

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

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