math programming help in shell
i am trying to do some math for a program, and i am getting an error. here is my code:
let perimeter=2*$l+2*$w error: rectangle: line 6: let: perimeter=2*: syntax error: operand expected (error token is "*") |
show us the entire script please.
[code][/code] tags Please. and bookmark these... http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html http://www.tldp.org/LDP/Bash-Beginne...tml/index.html http://www.gnu.org/software/bash/man...ode/index.html http://www.grymoire.com/Unix/Sh.html http://tldp.org/LDP/abs/abs-guide.pdf http://www.tldp.org/LDP/abs/html/ http://mywiki.wooledge.org/BashFAQ http://mywiki.wooledge.org/BashPitfalls |
The shell is not very good at doing math directly, but you can use other programs for this, such as bc.
Code:
perimeter=$(echo "2*$l+2*$w" | bc -l) |
Regular expressions ...
See; http://www.freeos.com/guides/lsst/ch02sec07.html You have to use escape characters to preserve mathematical functions... |
All times are GMT -5. The time now is 05:10 PM. |