L
L
lynnikvadim2015-01-14 18:48:24
bash
lynnikvadim, 2015-01-14 18:48:24

How to populate an array in bash?

How to fill an array of n elements using a loop (by entering each element from the keyboard in turn)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
3
3vi1_0n3, 2015-01-14
@lynnikvadim

for i in {1..n}
do
  read variable
  MY_ARRAY[i]=$variable
done

Then the whole array can be displayed like this:
echo ${MY_ARRAY[*]}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question