Each round loop var exchange

Asked

Viewed 31 times

1

I am developing a shell system that has a form to add some fields.

Quantity Product Valorunitario etc...

I need every time the loop changes a variable, so I call it in the form!

In the case is the Prev, at each round he switches to prev1, at the other prev2 switches to prevdois1, ai at the other round, prev2, prevdois2 and so on, this because I will call these variables to save in a form. some 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
  • You want to add in front 1, 2, 3 .... of the Prev string?

  • THAT! could be! is that I need to call these different variables in each round for a form! In case we will say that in the first step the Prev is worth avocado Prev=avocado in the second Prev it is worth pineapple 2prev=pineapple And so on!

  • I’ve never seen this asterisk-placing syntax * before the variable name

  • This because I put bold here on the site kkkkk, discard! I could not express myself right! I need each loop to change and stay fixed! So I can call in the form... since they are different products. Got it? the output will be in an HTML file, problem that the output as expected is always the last round. and I needed it to be independent... Example: <tr> <td>$Prev</td> <td>$prevdois</td> </tr> <tr> <td>$Prev</td>#Xa; <$prevdois</td> </tr>

1 answer

0

Use val with your accountant i:

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

When i = 1, the above result will be:

prev1=$Produto
prevdois1=$Quantidade

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.