The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Multi-Dimensional Arrays Octal High Level Programming 3 04-08-2007 04:58 AM
borne shell script migg-21 UNIX for Dummies Questions & Answers 1 02-26-2007 12:54 AM
Documenattion on Borne And C shell programming azazalis Shell Programming and Scripting 3 07-09-2006 10:56 AM
Need Help With My First Borne Shell Program FuzzyNips UNIX for Dummies Questions & Answers 3 11-04-2004 07:09 PM
duble dimensional arry in shell script krishna UNIX for Advanced & Expert Users 1 09-07-2001 10:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-15-2002
jparker jparker is offline
Registered User
  
 

Join Date: May 2002
Location: Falls Church, Va, USA
Posts: 3
Smile Can there be multi-dimensional variable arrays in borne shell?

Hello -

I've serached the web but can't find much on array script variables (except that C-shell variables are arrays!)

I'm trying to form a 2-D string array: (this is what I want, but in java)

String[][] list = { {"one", "two"}, {"three"} };

I know this is a 1-D string array shell variable:

list="one two"

but how can I get another dimension? (and then index them in borne shell?) (I acknowledge that it might not be possible)

Basically I'd like to have a single variable, it's first set of elements always get evaluated, and if a 2nd dimension exists, apply slightly different logic on all of the other elements.

Any ideas would be greatly appreciated.

Thanks, Sean

Last edited by jparker; 05-16-2002 at 09:43 AM..
  #2 (permalink)  
Old 05-15-2002
usfrog usfrog is offline
Registered User
  
 

Join Date: Dec 2001
Location: San Jose CA
Posts: 32
I'm afraid you might have to build such array through logic, at least in Korn Shell (ksh).

As you mentionned, here's what's truly available:

# Arrays : one dimensional arrays of integers or strings
# automatically dimensionned to 1024
animal[0]="dog" ; animal[1]="horse" ; animal[3]="donkey"
set -A flower tulip gardenia " " rose
print ${animal[*]}
print ${flower[@]}
print "cell#1 content : ${flower[1]}
  #3 (permalink)  
Old 05-15-2002
jparker jparker is offline
Registered User
  
 

Join Date: May 2002
Location: Falls Church, Va, USA
Posts: 3
Thanks so much -
It appears C-shell and K-shell like the [] syntax, but borne doesn't -

hopefully someone else has some ideas?

Cheers-
Sean
  #4 (permalink)  
Old 05-15-2002
Perderabo's Avatar
Perderabo Perderabo is online now Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
If you need arrays you really should consider switching to ksh or bash. If that is really not possible, you can use eval to simulate arrays but the syntax and quoting concerns are nasty....

# simulate a[index]=string
index=5
eval a${index}=string

What this really did of course is create a vaiable called a5 which got the value. But you also could have an a4 variable and so on.

# simulate echo ${a[index]}

eval echo \$a${index}

# simulate x=${a[index]}

eval x=\$a${index}
  #5 (permalink)  
Old 05-15-2002
jparker jparker is offline
Registered User
  
 

Join Date: May 2002
Location: Falls Church, Va, USA
Posts: 3
Thanks a lot - I know it looks nasty but it does what I wanted -
atleast I'm learning a bit more.

Cheers -

Sean
Closed Thread

Bookmarks

Tags
bash, bash eval, eval

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0