0

In shell script (!/bin/sh) I have array elements:

u[1]="someString"
u[2]="anotherString"
u[3]="aThirdString"
u[4]="aFourhString"

I want to build a new string, which will display the string values of u array elements that I want and separated by semi-column (;). I want to do the following:

totalString=""
for k in {2..4}; do
totalString+="${u[k]};"
done

But I cannot make it to work. First of all, for some reason k is interpreted like a {2..4} at the above, instead of evaluating the value of u[k] every time to finally display the desired:

anotherString;aThirdString;aFourhString

Note that the example array elements are not always the same as above example. I could have more than 4, or less. I am counting and define them with other part of code and I want to display some of them only at the total new string.

Kostas75
  • 331
  • 1
  • 4
  • 13
  • After some further investigation: a) The above is possible only using bash script. b) With Shell script, only the while loop can do the job, using manual counter increment ( i=(($i+1)) ) – Kostas75 Mar 14 '16 at 00:14
  • Hardly could anybody help you if you do not include the right tag as `shell`. – Jdamian Jun 20 '16 at 11:52

0 Answers0