**Addition of two int number with awk –**

echo $a $b | awk ‘{sum= $1 + $2 ; print sum }’

**Multiplication and division of two floating number with awk –**

echo $a $b | awk ‘{ printf( “%.3f\n”, ( $1 * 100 ) / $2 );}’

res=`echo $a $b | awk ‘{ sum = $1 * $2 ; per = sum / 100; print per}’`

**Mathematical operation with bc**

res=`echo “$sum * $avg / 100” |bc`

free_t=`echo “$free / 1024 / 1024” |bc`

**condition with bc –**

if [ $(echo “$a < $b”| bc) -eq 1 ]

It will return either 0 or 1 depending on true or false.

**Mathematical operation with bash **

avg=`echo $((( $sum * 60 ) / 100 ))`

### Like this:

Like Loading...

*Related*

This entry was posted on August 11, 2010 at 7:37 am and is filed under Shell scripts. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

## Leave a Reply