Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 23 Nov 2014, 07:33
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
"expr" command won't multiply
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [11 Posts]  
Author Message
Bruce B


Joined: 18 May 2005
Posts: 11131
Location: The Peoples Republic of California

PostPosted: 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

    # expr 10 * 5


(I don't think it is a Puppy or Busybox problem)
Back to top
View user's profile Send private message 
GuestToo
Puppy Master

Joined: 04 May 2005
Posts: 4078

PostPosted: 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
View user's profile Send private message 
GuestToo
Puppy Master

Joined: 04 May 2005
Posts: 4078

PostPosted: 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
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11131
Location: The Peoples Republic of California

PostPosted: 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
View user's profile Send private message 
GuestToo
Puppy Master

Joined: 04 May 2005
Posts: 4078

PostPosted: 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
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11131
Location: The Peoples Republic of California

PostPosted: 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
View user's profile Send private message 
Ian
Official Dog Handler


Joined: 04 May 2005
Posts: 1237
Location: Queensland

PostPosted: 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. Smile
Back to top
View user's profile Send private message 
GuestToo
Puppy Master

Joined: 04 May 2005
Posts: 4078

PostPosted: 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
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11131
Location: The Peoples Republic of California

PostPosted: 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
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11156
Location: Arizona USA

PostPosted: Tue 12 Jul 2005, 23:28    Post subject:  

Hey, that's postfix notation. Is busybox written in Forth?
Back to top
View user's profile Send private message 
GuestToo
Puppy Master

Joined: 04 May 2005
Posts: 4078

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [11 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0605s ][ Queries: 11 (0.0086s) ][ GZIP on ]