1819899 Members
2456 Online
109607 Solutions
New Discussion юеВ

mod operator in shell

 
SOLVED
Go to solution
andi_1
Frequent Advisor

mod operator in shell

Hi,

I have one more quick question:

Suppose, I have to perform the following division:

20/8 = 2.5

What can I use in shell so only 2 is returned?
tmp=20/8
and then tmp==2

Thank you.
2 REPLIES 2
Patrick Wallek
Honored Contributor
Solution

Re: mod operator in shell

Use bc

VAR=`echo "20/8" | bc`
echo $VAR
2

Note that the ` are the backward tic marks.
Mark Greene_1
Honored Contributor

Re: mod operator in shell

where A=2 and B=5

this will return just 2:
(( C = $B / $A ))

this wil return just the remainder, 1:
(( D = $B % $A ))


HTH
mark
the future will be a lot like now, only later