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.