Aerometric between variables

Hi Guys,

I want to know how to do aerometric operations between two variable in bash shell and tc shell.

I have pre defined variables as follows,

vatiable1=12
variable2=45

I want to get assigned the division of these two variable to another variable.
I used following command, but it is not working.

expr variavle3 = ($cariable1/$variable2)
echo $variable3

Please somebody tell me how should I correct my command.

Regards,
Mahesh

variable3 = $(($cariable1/$variable2))
echo $variable3

Regards,
Rahul.

Hi,

Thanks for the quick reply.

The given syntex is working fine. But problem is when the variable1<$variable2 the result gives as 0.

I tried to print it with printf aalso but it is not work.

please help to solved this.

Thanks
Mahesh

Or to include decimal-points use bc:-

variable3=`echo "scale=2;$variable1/$variable2|bc -l`

Syntex is not clear. It is not working

variable3=`echo "scale=2;$variable1/$variable2|bc -l`

Regards,
Mahesh

Try cutting and pasting the command rather than typing it. It should work in bash.

Also typing 'which bc' to see if you've got the bc processor in your path.

missing quote

It was indeed - should have taken my own advice and cut-and-pasted from the terminal!

Apologies for that. Cheers vgersh99.

Is it possibe to do this with out using bc ?

Regards,
Mahesn

Well awk can handle non-integer arithmetic, but not standard bash or tcsh.