Every round loop exchange var

1

I'm developing a shell system that has a form for adding some fields.

Product Quantity Unit Value etc ...

I need every time I loop the loop to change a variable, so I call it on the form!

In case it is prev, every round it switches to prev1, in the other prevdois switch to prevdois1, there in the other round, prev2, prevdois2 and so on, this is because I'm going to call these variables to save to a form. any help?

while [ "$sair" != "sair" ]; do
i=$((i+1))
for filter in Produto Quantidade Descricao PrecoUnitario PrecoTotal; do
    read -p "${filter}: " ${filter}$i


**prev=$Produto
prevdois=$Quantidade**
done
    read -p "Deseja sair? [sair] ou enter para continuar: " sair
done
    
asked by anonymous 26.09.2017 / 19:03

1 answer

0

Use eval with your i counter:

eval prev$i=$Produto
eval prevdois$i=$Quantidade

When i = 1 , the above result will be:

prev1=$Produto
prevdois1=$Quantidade

However, although it is possible to do this, I suggest you take a look at arrays to perform this task.

    
28.09.2017 / 20:15