Arithmetic problem with shell script

I have some problems writing scripts ... if someone can help me, it will be really good!

My script has:

VISITS=$((WR + RD));
SERVICE_DEMAND=$((VISITS*SERVICE_DEMAND));

And I get this error:

./calc_serv_demand.sh: line 12: 0.0895406: syntax error: invalid arithmetic operator (error token ".0895406")

Can someone help me?

I think because bash only works with an integer ... I need to use float values.

early


Problem resolved:

VISITS = $ (echo $ WR + $ RD | bc); echo $ VISITS

SERVICE_DEMAND = $ (echo $ VISITS '*' $ SERVICE_TIME | bc); echo $ SERVICE_DEMAND

+5
source share
5 answers

bc , ..

echo $WR + $RD | bc

..

+5

bc . Bash .

+3
+2

( ), :

WR=5
RD=7
VISITS=$[WR+RD]
SERVICE_DEMAND=.0895406
SERVICE_DEMAND=`echo "scale=5; $VISITS * $SERVICE_DEMAND" |bc -l`
echo Service Demand = $SERVICE_DEMAND

:

Service Demand = 1.0744872

scale = 5 5 ; ( bc -l), .

+2

, bc, .

- :

echo ($WR+$RD)*$SERVICE_DEMAND | bc

+1
source

All Articles