mardi 16 novembre 2021

Convert excel formula to linux bash script

I'm trying to convert the following excel-formula into a simple bash script:

=IF(B3*10>B5,1,IF(TRUNC(B5/B3/10)>3,3,TRUNC(B5/B3/10)))

Examples:

  • If B3="2" and B5="39"; the output ("VAL") should be 1
  • If B3="2" and B5="40"; the output ("VAL") should be 2
  • If B3="2" and B5="60"; the output ("VAL") should be 3

This is what I've tried, but the output is not correct:

if (( $B3 \* 10 > $B5 )); then
if (( $B5 \/ $B3 \/ 10 > 3 )); then
VAL="3"
else
VAL=`expr $B5 \/ $B3 \/ 10`
fi fi

Where is the error? :)

Aucun commentaire:

Enregistrer un commentaire