#!/bin/bash
# How to make a random matrix in bash in that program,
# I don't understand how to make a random matrix in shell script.
# read the matrix order
read -p "Give rows and columns: " n
# accept elements
echo "Matrix element:"
let i=0
while [ $i -lt $n ]
do
let j=0
while [ $j -lt $n ]
do
read x[$(($n*$i+$j))]
j=$(($j+1))
done
i=$(($i+1))
done
如果您只查看显示数字排列就好像它们是在一个n X n矩阵中一样,那么下面将给你一些关于如何获得随机数并将它们传递给"格式化"的想法。脚本的一部分。
#!/bin/sh
# read the matrix order
read -p "Enter dimension of symmetric matrix: " n
count=$(( $n * $n ))
NUMBERS="./numbers.txt"
shuf -n ${count} --input-range=0-99 >"${NUMBERS}"
# accept elements
echo "Matrix element:"
i=0
while [ $i -lt $n ]
do
j=0
while [ $j -lt $n ]
do
read pos
echo "t${pos}c"
j=$(($j+1))
done
echo ""
i=$(($i+1))
done <"${NUMBERS}"