I am having a problem with the bc command. The output generated is:
(standard_in) 2: syntax error
Here I post my code, any suggestions will be appreciated.
value="100%" # the threshold to cause a break out
kb="kB/s"
mb="MB/s" # strings to mask out
conversor=1024 # kb->mb conversion
contador=0 # initalize our total in megabytes
for ((x=3; x<=${#array[@]}; x+=5)); do
paraula=${array[$x]};
if [[ $paraula =~ .*kB.* ]]; then
paraula=${paraula%$kb}
paraula=$(echo "scale=4; $paraula/$conversor" | bc) # convert to $mb
contador=$(echo "scale=4; $contador+$paraula" | bc)
echo "Counting: "$contador
else
paraula=${paraula%$mb}
contador=$(echo "scale=4; $contador+$paraula" | bc)
echo "Counting: "$contador
fi
if [[ " ${array[$x]} " =~ " $value " ]]; then
break;
fi
echo "Value : ${array[$x]} ";
done
echo "final value: $contador"
then, the error on the terminal after execute the script is

bc.bash -x yourscriptto log everything the script does, to find the place where it first goes wrong. If you want the tracking to be a bit easier, you can assign a value toPS4that includes line number; for example, all on one line you could run:PS4=':${LINENO}+' bash -x yourscript. (Note that for security reasons,PS4has to be set inside your script itself in very new versions of bash if that script is running as root).echothe values ofparaulaandcontadorbefore you feed it tobc?