0

I would like to concatenate the variable name with shell using the folowing example

val=23
    for i in 1 2 3 4 
    do   
    a$i=$val + $i 
    done

but I got error -ash: a1=x: not found !!

how can I concatenate variable name with shell

the purpose is to get a1=24; a2=25 ...

Anis_Stack
  • 3,306
  • 4
  • 30
  • 53
  • You want to review [arithmetic expressions](https://stackoverflow.com/a/6348941/21567) and [dynamic variable names](https://stackoverflow.com/a/18124325/21567) - both assuming you're using bash (or a close bourne-shell relative) here. – Christian.K Nov 26 '18 at 13:17
  • The usual response to questions like this is "why don't you use an array"? – tripleee Nov 26 '18 at 13:26
  • the array is not supported with ash – Anis_Stack Nov 26 '18 at 13:32
  • @Anis_Stack you specified `bash` in the tags, so it's not a surprise that it got marked as a duplicate the bad/dangerous way of accomplishing this is via eval; but even with that, the math operator on the line won't work either, so the question is what is it trying to do? – Anya Shenanigans Nov 26 '18 at 13:44
  • @Petesh: you are right sorry for the mistake – Anis_Stack Nov 26 '18 at 13:46

0 Answers0