This is the code that I have wrote in bash. The array arrKey
is taking the user input and it's working well when I check. but I want to assign the elements in arrKey[]
into new array K1[]
, then values are changing. For arrKey[0,1]
and arrKey[1,0]
, I want to assign minus value in order to find the determinant of matrix later.
This is the Code:
declare -A arrKey
for ((i=0; i<2; i++)) do
for((j=0; j<2;j++)) do
read -p "Enter the key [$i, $j] = : " num
arrKey[$i,$j]=$num
done
done
declare -a K1
K1[0,0]="$((arrKey[1,1] ))"
K1[0,1]="$((0 - arrKey[0,1] ))"
K1[1,0]="$((0 - arrKey[1,0] ))"
K1[1,1]="$((arrKey[0,0] ))"
echo ${arrKey[0,0]}
echo ${arrKey[0,1]}
echo ${arrKey[1,0]}
echo ${arrKey[1,1]}
echo
echo ${K1[0,0]}
echo ${K1[0,1]}
echo ${K1[1,0]}
echo ${K1[1,1]}
When I run array K1[]
values not as expected.
Enter the key [0, 0] = : 1
Enter the key [0, 1] = : 2
Enter the key [1, 0] = : 3
Enter the key [1, 1] = : 4
1
2
3
4
-3
1
-3
1
Expected Output:
Enter the key [0, 0] = : 1
Enter the key [0, 1] = : 2
Enter the key [1, 0] = : 3
Enter the key [1, 1] = : 4
1
2
3
4
4
-2
-3
1