Sometimes I need to divide one number by another. It would be great if I could just define a bash function for this. So far, I am forced to use expressions like
echo 'scale=25;65320/670' | bc
but it would be great if I could define a .bashrc function that looked like
divide () {
bc -d $1 / $2
}
Best Answer
I have a handy bash function called
calc
:Example usage:
You can change this to suit yourself. For example:
Note:
<<<
is a here string which is fed into the stdin ofbc
. You don't need to invokeecho
.