I create an array of ranges and print their number of elements:
arrayRanks=({A..D} {1..4})
echo "El array tiene ${#arrayRanks[*]} elementos"
I can add an element to the end of the array while updating its number of elements:
arrayRanks[${#arrayRanks[*]}]=33
echo "El array ahora tiene ${#arrayRanks[*]} elementos"
So far so good, but if I want to add a range or a set of elements through a range at the end of the array or at the beginning, how can I do it?
You are adding a range using the expression
bla=(cosas)
and it works perfectly.To add more elements to an array you must use
bla+=(más cosas)
. Notice that it is exactly the same expression, but with+=
:To add data to the beginning, it occurs to me to redefine the array using
array=(nuevos elementos "${arrayInicial[@]}")
: