S
S
Sergey2015-12-04 20:15:02
linux
Sergey, 2015-12-04 20:15:02

How to use a variable in the name of another variable in bash?

There is a for i in 10 loop.
How can I use a variable whose name depends on $i in it?
Those. there are variables
disk_1
disk_2
and I want to use something like
$disk_$i in the loop

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2015-12-04
@butteff

KVM_VM_DISK_SIZE_2='20000'
prefix='KVM_VM_DISK_SIZE_'
i=2
size=$(eval echo "\$$prefix$i")
echo $size

result:
20000

D
Duha666, 2015-12-04
@Duha666

Use array

O
Oleg, 2014-03-16
@th_alex

startandroid.ru/ru
habrahabr.ru/post/164853
habrahabr.ru/post/193122
progbook.ru/android

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question