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 Wed 26 Nov 2014, 07:21
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 Posts_count  
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: 11164
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:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0568s ][ Queries: 12 (0.0073s) ][ GZIP on ]