| Author |
Message |
Bruce B

Joined: 18 May 2005 Posts: 10818 Location: The Peoples Republic of California
|
Posted: Tue 12 Jul 2005, 15:15 Post subject:
"expr" command won't multiply |
|
Maybe someone would kindly explain to me why I can't multiply with expr on the command line. (I'm using a US keyboard)
This works
# expr 10 + 5
# expr 10 - 5
# expr 10 / 5
But not
(I don't think it is a Puppy or Busybox problem)
|
|
Back to top
|
|
 |
GuestToo
Puppy Master
Joined: 04 May 2005 Posts: 4078
|
Posted: Tue 12 Jul 2005, 16:17 Post subject:
|
|
i don't know
this works using bash:
# let "z=2*3"
# echo $z
6
|
|
Back to top
|
|
 |
GuestToo
Puppy Master
Joined: 04 May 2005 Posts: 4078
|
Posted: Tue 12 Jul 2005, 16:22 Post subject:
|
|
or this works in bash:
# echo $((2*3))
6
it's supposed to be faster than expr, because it's built into the bash executable, and you don't have to start the expr binary running
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10818 Location: The Peoples Republic of California
|
Posted: Tue 12 Jul 2005, 16:54 Post subject:
|
|
Thanks!
If you can't do it, then I really give up multiplying with expr.
So I just made a script for simple calculations following your model.
The script doesn't like spaces so I used $1
| Code: | #!/bin/sh
echo $(("$1")) |
|
|
Back to top
|
|
 |
GuestToo
Puppy Master
Joined: 04 May 2005 Posts: 4078
|
Posted: Tue 12 Jul 2005, 19:48 Post subject:
|
|
you need to escape the * symbol
because the shell uses the * symbol for it's own purposes
expr 2 * 3 won't work
expr 2 \* 3 will work
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10818 Location: The Peoples Republic of California
|
Posted: Tue 12 Jul 2005, 19:58 Post subject:
|
|
Cool. Thanks! I thought I'd tried every combination - but this one really works.
|
|
Back to top
|
|
 |
Ian
Official Dog Handler

Joined: 04 May 2005 Posts: 1237 Location: Queensland
|
Posted: Tue 12 Jul 2005, 22:06 Post subject:
|
|
I put everyone through this one in the chat room a couple of weeks ago until I worked it out.
|
|
Back to top
|
|
 |
GuestToo
Puppy Master
Joined: 04 May 2005 Posts: 4078
|
Posted: Tue 12 Jul 2005, 22:19 Post subject:
|
|
there's also bc and dc
http://directory.fsf.org/GNU/bc.html
which can handle floating point numbers
interestly, Puppy's Busybox seems to have a minimal integer version of dc (command line rpn calculator)
maybe i'll make a bc/dc dotpup, they aren't big, maybe 60k each
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10818 Location: The Peoples Republic of California
|
Posted: Tue 12 Jul 2005, 22:38 Post subject:
|
|
Nice catch on the busybox dc! I made a link for it, and I think it does handle floating points somewhat.
Try 6 4 /
or
6.5 8 +
|
|
Back to top
|
|
 |
Flash
Official Dog Handler

Joined: 04 May 2005 Posts: 9850 Location: Arizona USA
|
Posted: Tue 12 Jul 2005, 23:28 Post subject:
|
|
Hey, that's postfix notation. Is busybox written in Forth?
|
|
Back to top
|
|
 |
GuestToo
Puppy Master
Joined: 04 May 2005 Posts: 4078
|
Posted: Tue 12 Jul 2005, 23:47 Post subject:
|
|
dc is a command line RPN calculator
(the reason for the post-fix syntax)
Forth is more fun than any other language i've tried
besides, Elizabeth Rather looks a bit like Battlestar Galactica's President Laura Roslin - Mary McDonnell)
i used to run FIG-Forth on my ZX81
|
|
Back to top
|
|
 |
|