Help need for shell script
HI ,
I need help regarding the shell scripting . I used the following commands on Centos flavoured linux Code:
x=1000 Quote:
Thanks. |
Try expr ${x} / ${y} . Without the $ "x" means a literal x, the $x (or, pedantically, ${x}) means "the value of the variable x.
Here's an example: Code:
$ x=1000;y=1;expr ${x} / ${y}; expr ${y} / ${x} By the way, the expr command is not really necessary. Consider this: Code:
$ x=1000;y=1;echo $((${x} / ${y}));echo $((${y} / ${x})) Code:
$ x=1000;y=1;echo "scale=3;${x} / ${y}" | bc;echo "scale=3;${y} / ${x}" | bc |
This page should give you all you need to know about doing integer arithmetic in the shell:
http://mywiki.wooledge.org/ArithmeticExpression There's also a link on that page to another one describing how to do floating-point math. Floating point nearly always requires an external tool. And as pointed out, expr is pretty much completely superfluous these days. It's probably best to just forget that it exists at all. (Actually, it does have one or two other features that can still come in handy, but only on very rare occasions. You certainly don't need it for doing math.) |
I thought I would add to the following example by David:
Quote:
Code:
$ x=1000;y=1;echo $(( x / y ));echo $(( y / x )) |
Thanks guys it help me a lot . Thank you so much !!!
|
Please mark as SOLVED once you have a solution
|
All times are GMT -5. The time now is 07:16 PM. |