L
L
link772018-07-06 18:01:55
bash
link77, 2018-07-06 18:01:55

How to substitute the number of elements of an array into a bash variable?

Good afternoon.
For example:
There is an array ${{my_array[@]}, data comes to it from a function.
If I write
echo ${{#my_array[@]}
Outputs: 11 The
question is, how can I substitute this number 11 into a variable??
i=${{#my_array[@]} - doesn't roll (

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Ratkin, 2018-07-06
@Hanharr

i=`echo ${#my_array[@]}`
echo $i

J
jcmvbkbc, 2018-07-06
@jcmvbkbc

i=${{#my_array[@]} - doesn't roll (

Too many brackets. Must be
i=${#my_array[@]}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question