"expr" command won't multiply

Using applications, configuring, problems
Post Reply
Message
Author
Bruce B

"expr" command won't multiply

#1 Post by Bruce B »

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
  • # expr 10 * 5
(I don't think it is a Puppy or Busybox problem)

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#2 Post by GuestToo »

i don't know
this works using bash:

# let "z=2*3"
# echo $z
6

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#3 Post by GuestToo »

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

Bruce B

#4 Post by Bruce B »

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: Select all

#!/bin/sh
echo $(("$1"))

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#5 Post by GuestToo »

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

Bruce B

#6 Post by Bruce B »

Cool. Thanks! I thought I'd tried every combination - but this one really works.

User avatar
Ian
Official Dog Handler
Posts: 1234
Joined: Wed 04 May 2005, 12:00
Location: Queensland

#7 Post by Ian »

I put everyone through this one in the chat room a couple of weeks ago until I worked it out. :-)

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#8 Post by GuestToo »

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

Bruce B

#9 Post by Bruce B »

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 +

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#10 Post by Flash »

Hey, that's postfix notation. Is busybox written in Forth?

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#11 Post by GuestToo »

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

Post Reply