Bourne Shell and Arrays


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bourne Shell and Arrays
# 1  
Old 07-25-2005
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  
Old 07-25-2005
Code:
if eval [ "\$DATA$x" = "element0" ]; then echo element 0 found; fi

or
Code:
eval [ "\$DATA$x" = "element0" ]&& echo element 0 found

# 3  
Old 07-25-2005
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Cybersecurity

'Shell Shock' vulnerability in Bourne shell

A severe vulnerability was discovered in Bourne shell. Just google for: bash vulnerability ... for more details. (5 Replies)
Discussion started by: Cochise
5 Replies

2. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

3. Shell Programming and Scripting

Bourne/C shell help

Exercise Five Write a Bourne shell script which: • Professionalism: plan for this from the start. • Has one command line argument. • If the command line argument is a directory then the script should output the number of files in the directory. • If the command line argument is an ordinary... (2 Replies)
Discussion started by: moesom
2 Replies

4. Shell Programming and Scripting

Is there any command in the Bourne shell?

Hi, The problem I have is that I want to create a list of folders whose names are read from a text file but the file names are in decimal. Each letter consists of an octet and the end of the folder name is defined by the white space character (0032) For example, we have in the text... (2 Replies)
Discussion started by: Gengis-Kahn
2 Replies

5. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

6. Shell Programming and Scripting

I need to understand the differences between the bash shell and the Bourne shell

I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done. I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
Discussion started by: awk_sed_hello
7 Replies

7. UNIX for Dummies Questions & Answers

Bourne-again shell

Hi guys !! well i'm still new in learning UNIX , and actually i'm still studying it by myself .. anyway, some people told me the Bourne-again shell is a good version of UNIX to work on , and i tried to download yesterday but i didn't know how to start it ...... the ReadMe file associated with... (3 Replies)
Discussion started by: mrsamer
3 Replies

8. Shell Programming and Scripting

bourne shell programming help

hey, i have 2 files... orders and products how do i do calculations on the order using the products ? say if the products file is: a123:shirt:10.00 zz123:nice shirt:19.95 and the order file is: 05/08/30 a123 10 zz123 3 Jun-3-1994 a123 2 2005.06.23 a123 2 (1 Reply)
Discussion started by: ganjakh0r
1 Replies

9. UNIX for Dummies Questions & Answers

Bourne Shell Script

Hello, I'm throwing this out there as a novice to the Unix world...I've been working on a project that requires me to ouput (using the echo command) a list of names in a single column format, but the problem is the input is in row format followed by a blank space...If anyone could give me a... (2 Replies)
Discussion started by: dmhonor914
2 Replies

10. Shell Programming and Scripting

bourne shell script

Hi all, Can somebody answer the following query Thanks, Srinivas A shell program that takes one or any number of file directory names as input; sorts the directories given as parameters jointly in the ascending or decending order of choice For EX : dips abc etc desc will sort the files... (2 Replies)
Discussion started by: psrinivas
2 Replies
Login or Register to Ask a Question