removido
(usa Nenhuma)
Enviado em 24/04/2016 - 22:36h
http://stackoverflow.com/questions/16487258/how-to-declare-2d-array-in-bash
You can simulate them for example with hashes, but need care about the leading zeroes and many other things. The next demonstration works, but it is far from optimal solution.
declare -A matrix
num_rows=4
num_columns=5
for ((i=1;i<=num_rows;i++)) do
for ((j=1;j<=num_columns;j++)) do
matrix[$i,$j]=$RANDOM
done
done
f1="%$((${#num_rows}+1))s"
f2=" %9s"
printf "$f1" ''
for ((i=1;i<=num_rows;i++)) do
printf "$f2" $i
done
echo
for ((j=1;j<=num_columns;j++)) do
printf "$f1" $j
for ((i=1;i<=num_rows;i++)) do
printf "$f2" ${matrix[$i,$j]}
done
echo
done
Resumindo: você cria bidimensionais simulando com hashes. Para usar hash, você usa o comando declare com a opção
-A .
Obs 1: na página citada tem mais soluções.
Obs 2: eu conheço um pequeno truque sujo, mas não vale a pena. Essa solução do texto é melhor.
----------------------------------------------------------------------------------------------------------------
# apt-get purge systemd (não é prá digitar isso!)
Encryption works. Properly implemented strong crypto systems are one of the few things that you can rely on. Unfortunately, endpoint security is so terrifically weak that NSA can frequently find ways around it. — Edward Snowden