The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
I need help with arrays in C Shell domain Shell Programming and Scripting 5 11-19-2008 08:17 AM
how to use arrays in c shell hgphsf Shell Programming and Scripting 6 12-14-2007 02:03 PM
Bourne-again shell mrsamer UNIX for Dummies Questions & Answers 3 09-30-2006 02:42 AM
Bourne Shell scripting help PoloRL185 Shell Programming and Scripting 1 05-13-2005 12:09 PM
bourne shell not working gillbates Shell Programming and Scripting 6 06-17-2004 04:22 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-25-2005
Unbeliever Unbeliever is offline
Registered User
  
 

Join Date: Jul 2005
Location: England
Posts: 183
Bourne Shell and Arrays

Hi everyone, first post here so please be gentle :-)

I normally likle to script in Bourne Shell simply for guarenteed compatibility across any system I might run across but this latest problem has me stumped.

Arrays is a rather significant construct missing from sh and after finding a way to 'fudge' them using eval I thought I found the solution to my problem. However I cant seem to get it to work in all circumnstances. I wont go into all the details, I'll just give you a trivial example.

x=0
eval DATA${x}="element$x"
x=`expr $x + 1`
eval DATA${x}="element$x"
x=0
eval echo \$DATA$x
x=`expr $x + 1`
eval echo \$DATA$x

This correct echos "element0" and "element1". However what I cannot get to work is using the eval within a test construct. What I would like to do is this:

if [ "`eval echo \$DATA$x`" = "element0" ]
then
echo element 0 found
fi

but it just doesnt work. the eval works fiune standalone but withing back quotes it doesn't. I am obviously misunderstanding something as to how back quote execution, eval, or possibly both work. So I dont know even if its possible to do this at all.

I've tried all sensible (and not so sensible) combinations of quotationa dn escaping to no avail.

Any help appreciated.

Sean Timmins
  #2 (permalink)  
Old 07-25-2005
r2007's Avatar
r2007 r2007 is offline
Registered User
  
 

Join Date: Jun 2005
Location: China
Posts: 73
Code:
if eval [ "\$DATA$x" = "element0" ]; then echo element 0 found; fi
or
Code:
eval [ "\$DATA$x" = "element0" ]&& echo element 0 found
  #3 (permalink)  
Old 07-25-2005
Unbeliever Unbeliever is offline
Registered User
  
 

Join Date: Jul 2005
Location: England
Posts: 183
Gah! Thanks for that r2007, it works fine now.

I had to escape all the double quotes in the test because I was actually testing for the presence of a null string but other than that its good.
Closed Thread

Bookmarks

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 09:49 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