I am getting the error: "line 9: 0.0000: syntax error: invalid arithmetic operator (error token is ".65")":
Please suggest how to fix this
Tried this:
#!/bin/bash
IFS=' ' read -r -a pids <<< $(echo $(pgrep nr-softmodem -d ' ') )
cpu_sum=0.0000;
mem=0;
for i in "${pids[@]}";
do
cpu=$(top -b -n1 -p "$i" -H | tail -n +8 | awk '{ if ($9 !=0) {sum += $9; count++} } END {if (count !=0) {avg =sum/count; print avg}}')
cpu_sum=$(echo $((cpu_sum +=cpu )))
done
echo "$cpu_sum"
Expected output:
56.65
Output seen:
./top_gNB1.sh: line 9: 0.0000: syntax error: invalid arithmetic operator (error token is ".0000")
./top_gNB1.sh: line 9: 56.65: syntax error: invalid arithmetic operator (error token is ".65")
0
$(echo $(( ... ))). It's equivalent to just doing$(( ... )). Also, add a space after the parentheses.