0

First i will take value of yesterday & Today file size in bytes (a=yesterday & b=today)

I need to calculate the percentage and find out if difference greater than or less than 10%

a=21007558 -- Yesterday
b=19330    -- Today 

c=`expr ((($b/$a) "*" 100) "-" 100) | bc` 

This is not working

1
  • 1
    Note that, if this is your actual code, the variables a and b will be empty: -- is not the shell's comment mechanism. You'll see this error: bash: --: command not found. I can explain further if requested. Commented Aug 26, 2016 at 13:17

1 Answer 1

2

you can use scale option as below;

c=$(echo "scale=6;((($b/$a) * 100) -100)" | bc)
echo $c

to lest than or greter than %10; you can try as below;

let c=$(echo $(printf %.$2f $(echo "scale=6;((($b/$a) * 100) -100)" | bc)))
if [[ c -lt -10  ]]; then
echo "decrease rate is %"$c    
fi
if [[ c -gt 10  ]]; then
echo "increase rate is %"$c    
fi
Sign up to request clarification or add additional context in comments.

1 Comment

@senthil; I update ans. added if statement < or > 10%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.