我一直在疯狂地试图弄清楚这种语法......谁能指出我正确的方向?
#Counter to iterate through the ENTIRE affinity array
affArrayCtr=0
#Counter to go through 4 cores for EACH pid
affCtr=0
#Counter to go through each PID to keep track of which PID we are on
pidCtr=0
#Affinity array size
affArraySz=${#affConfigArray[@]}
#Each core's new affinity, strings initialized to empty
pid0Aff=
pid1Aff=
pid2Aff=
pid3Aff=
while [ $affArrayCtr -lt $affArraySz ]; do
while [ $affCtr -lt $NUMCORES ]; do
if [[ ${affConfigArray[$affArrayCtr]} -eq 1 ]]; then
tempAff0="$(pid"${pidCtr}"Aff)"
tempAff1=$(($affArrayCtr % 4))
pid${pidCtr}Aff="$tempAff0 $tempAff1"
affCtr=$(($affCtr + 1))
affArrayCtr=$(($affArrayCtr + 1))
fi
affArrayCtr=$(($affArrayCtr + 1))
affCtr=$(($affCtr + 1))
done
affCtr=0
pidCtr=$(($pidCtr + $NUMCORES))
done
echo "Final affinity strings before adding the commas"
echo $pid0Aff
问题是我尝试分配的位置tempAff0="$(pid"${pidCtr}"Aff)"
以及尝试进行最终连接的时间pid${pidCtr}Aff="$tempAff0 $tempAff1"
。
我尝试在使用数组而不是字符串的地方进行更改,但是,我的数组名称包含变量这一事实仍然存在问题:
#Each core's new affinity, arrays initialized to empty
declare -a pid0Aff
declare -a pid1Aff
declare -a pid2Aff
declare -a pid3Aff
while [ $affArrayCtr -lt $affArraySz ]; do
affCtr=0
while [ $affCtr -lt $NUMCORES ]; do
if [[ ${affConfigArray[$affArrayCtr]} -eq 1 ]]; then
tempAff=$(($affArrayCtr % 4))
pid${pidCtr}Aff[${#pid${pidCtr}Aff[*]}]="$tempAff"
affCtr=$(($affCtr + 1))
affArrayCtr=$(($affArrayCtr + 1))
fi
罪魁祸首是我想附加到数组的地方:
pid${pidCtr}Aff[${#pid${pidCtr}Aff[*]}]="$tempAff"