fix: correct jq syntax for updating stats
- Adjusted the jq command for adding values to arrays to use the correct syntax for accessing keys. - Updated the jq command for updating numeric values to use the `--argjson` option for proper type handling. These changes ensure that the script correctly updates the statistics file without errors, improving the reliability of the data handling.
This commit is contained in:
parent
ca6a80da97
commit
b8b2ee6972
@ -38,12 +38,12 @@ update_stats() {
|
|||||||
|
|
||||||
if [ "$type" = "array" ]; then
|
if [ "$type" = "array" ]; then
|
||||||
# 添加到数组
|
# 添加到数组
|
||||||
jq --arg key "$key" --arg value "$value" \
|
jq --arg value "$value" \
|
||||||
".details[$key] += [\$value]" "$STATS_FILE" > "$STATS_FILE.tmp"
|
".details.$key += [\$value]" "$STATS_FILE" > "$STATS_FILE.tmp"
|
||||||
else
|
else
|
||||||
# 更新数值
|
# 更新数值
|
||||||
jq --arg key "$key" --arg value "$value" \
|
jq --arg key "$key" --argjson value "$value" \
|
||||||
".[$key] = ($value | tonumber)" "$STATS_FILE" > "$STATS_FILE.tmp"
|
".$key = \$value" "$STATS_FILE" > "$STATS_FILE.tmp"
|
||||||
fi
|
fi
|
||||||
mv "$STATS_FILE.tmp" "$STATS_FILE"
|
mv "$STATS_FILE.tmp" "$STATS_FILE"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user