ramalaks
asked on
Array in bourne shell?
Can we simulate a array in bourne shell? If yes, how?
ASKER
You mean, form the string in such a way that it appears as array element?
Will this work if the array size is not known?
Will this work if the array size is not known?
What array operations do you want to simulate?
ASKER
I will have to use array of strings and the size is based on the input argument to the shell script which is not a fixed value.
You haven't answered the fundamental question posed by my original post. Are you using genuine olde fashioned Bourne shell, or aren't you? If you're writing your own script, that sounds like you're under no constraints as far as what scripting language you use, so you can use one that's based on POSIX.2 compliant shell such as Korn Shell (ksh). Actually, most modern .*x systems have a POSIX compliant /bin/sh as well.
The syntax looks like this
index=257
vbl["$index"]=hello
echo "${vbl[$index]}"
There's no need to pre-declare the size of the array (as there was in early version of Korn Shell).
The syntax looks like this
index=257
vbl["$index"]=hello
echo "${vbl[$index]}"
There's no need to pre-declare the size of the array (as there was in early version of Korn Shell).
ASKER
Sorry chris, It is old fashioned bourne shell which does not support arrays.
That is why, I asked if we can simulate by string cat to form variables look like array. I dont know how to do that.
Yes, Csh, and Ksh support arrays. I can always use ksh. But I was curious to know how to simulate array in bourne becuase, I have done almost 50% of my script in Bourne..at one point I will need an array. Thanks
I still want to know how do we simulate array in bourne shell?
That is why, I asked if we can simulate by string cat to form variables look like array. I dont know how to do that.
Yes, Csh, and Ksh support arrays. I can always use ksh. But I was curious to know how to simulate array in bourne becuase, I have done almost 50% of my script in Bourne..at one point I will need an array. Thanks
I still want to know how do we simulate array in bourne shell?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
eval "array_$no='$i'"
eval echo "$"array_$no""
Works. Thanks and points to chris.
eval echo "$"array_$no""
Works. Thanks and points to chris.
get_value name_number
set_value name_number value
but this would be greatly complicated by the fact that genuine olde fashioned Bourne shell also does not support shell functions.