I have been going crazy trying to figure out this syntax...can anyone point me in the right direction?
#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
The problem is where I try to assign tempAff0="$(pid"${pidCtr}"Aff)" and when I try to do a final concatenation pid${pidCtr}Aff="$tempAff0 $tempAff1".
I attempted to make the change where I use arrays instead of strings, however, I am still having an issue with the fact that my array name contains a variable:
#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
The culprit is here where I want to append to the array:
pid${pidCtr}Aff[${#pid${pidCtr}Aff[*]}]="$tempAff"