我在bash中有很多数组,例如arrKey[]、aarT[]、P[],我想对这些数组执行算术操作。正如我所检查的,数组工作得很好,但是,查找数组P[]的算法是错误的。有人能帮我吗,拜托?
#The format is C[0] = (A[0,0]*B[0]) + (A[0,1]*B[1]) 这是我迄今为止尝试过的代码。
P[0]= $(({arrKey[0,0]} * {arrT[0]} ))+ $(({arrKey[0,1]} * {arrT[1]})) ))
echo ${P[0]}发布于 2016-08-21 15:40:09
代码行有几个问题:
P[0]= $(({arrKey[0,0]} * {arrT[0]} ))+ $(({arrKey[0,1]} * {arrT[1]})) ))=之后还有一个额外的空间,擦除它。
P=$({arrKey0,0}* {arrT} )+ $(({arrKey0,1} *{arrT1})$或从$(( … ))中的变量中删除{…}:
P=$(( arrKey0,0 * arrT + arrKey0,1 * arrT1 ))另外,请确保arrKey已声明为关联数组:
declare -A arrKey以确保预期的双索引0,0工作。
https://stackoverflow.com/questions/39065319
复制相似问题