I am trying to multiply array values with values derived from the multiplication of a loop index using bc.
#!/bin/bash n=10.0 bw=(1e-3 2.5e-4 1.11e-4 6.25e-5 4.0e-5 2.78e-5 2.04e-5 1.56e-5 1.29e-5 1.23e-5 1.0e-5) for k in {1..11};do a=$(echo "$n * $k" | bc) echo "A is $a" arn=${bw[k-1]} echo "Arn is $arn" b=$(echo "$arn * $a" | bc -l) echo "b is $b" #echo $a $b done
I am able to echo the array values by assigning it to a new variable within the loop, but when I use that to multiply using bc
, I get (standard_in) 1: syntax error
. I searched for clues and tried some but none helped. The expected output is as follows.
10 1.00E-02 20 5.00E-03 30 3.33E-03 40 2.50E-03 50 2.00E-03 60 1.67E-03 70 1.43E-03 80 1.25E-03 90 1.16E-03 100 1.23E-03 110 1.10E-03
All help is greatly appreciated.