Here's a refactored version of the function that does not use the `$statsInfo` array:
```
function addModelToIndexFile {
responseWords=$(wc -w < "$modelFile" | awk '{print $1}')
responseBytes=$(wc -c < "$modelFile" | awk '{print $1}')
while read -r line; do
value=$(echo "$line" | cut -d ':' -f2)
if [[ -n "$value" ]]; then
echo "
$model | $responseWords | ${responseBytes} | ${value} |
" >> "$indexFile"
fi
done < "$statsFile"
}
```
This version directly reads the `$statsFile` and outputs the values to the index file without using an array. It also fixes a bug in your original code where you were only outputting a `` element if the `value` variable was not empty, which could cause the table row to be incomplete if some of the statistics were missing.
|