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 Thu 08 Dec 2016, 12:09
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Division, Addition, Subtraction and Multiplication
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
LazY Puppy


Joined: 21 Nov 2014
Posts: 1573
Location: Germany

PostPosted: Wed 17 Feb 2016, 14:05    Post subject:  Division, Addition, Subtraction and Multiplication
Subject description: What am I doing wrong?
 

Hi.

This works: STEPS=$(( $SECONDS / 100 ))
Also this: STEP=$(( $STEP + 2 ))
This won't work: STEPS=$(( $SECONDS * 60 ))

How to do a multiplication in bash?

Thanks

Edit:

Sorry, the problem was a typo I found yet. Rolling Eyes

So this works of course also: STEPS=$(( $SECONDS * 60 )) Embarassed

_________________
RSH

T.O.P.L.E.S.S..

Das Schwert der Diffamierung ist stumpf geworden und der Schild der Ignoranz löchrig. Gut so! Cool Very Happy Laughing
Back to top
View user's profile Send private message 
slavvo67

Joined: 12 Oct 2012
Posts: 1207
Location: The other Mr. 305

PostPosted: Wed 17 Feb 2016, 22:00    Post subject:  

Maybe this link will help. Different format but it appears to work.

http://www.murga-linux.com/puppy/viewtopic.php?t=101416
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1149
Location: Japan

PostPosted: Wed 17 Feb 2016, 22:36    Post subject: Re: Division, Addition, Subtraction and Multiplication
Subject description: What am I doing wrong?
 

LazY Puppy wrote:
This won't work: STEPS=$(( $SECONDS * 60 ))
Why not?
Quote:
So this works of course also: STEPS=$(( $SECONDS * 60 ))
"Of course"? Where is the difference? I understand that you edited your post, but if you also edited your typo the whole post becomes confusing.

BTW: Depending on what you want to calculate your example might produce unexpected results. What do you expect as a result for variable STEP in following example? "Of course" 300 I hope...
Code:
#!/bin/bash
SECONDS=2
sleep 3
STEP=$(( $SECONDS * 60 ))
echo $STEP
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 1573
Location: Germany

PostPosted: Wed 17 Feb 2016, 23:40    Post subject: Re: Division, Addition, Subtraction and Multiplication
Subject description: What am I doing wrong?
 

MochiMoppel wrote:
LazY Puppy wrote:
This won't work: STEPS=$(( $SECONDS * 60 ))
Why not?
Quote:
So this works of course also: STEPS=$(( $SECONDS * 60 ))
"Of course"? Where is the difference? I understand that you edited your post, but if you also edited your typo the whole post becomes confusing.

BTW: Depending on what you want to calculate your example might produce unexpected results. What do you expect as a result for variable STEP in following example? "Of course" 300 I hope...
Code:
#!/bin/bash
SECONDS=2
sleep 3
STEP=$(( $SECONDS * 60 ))
echo $STEP

No, I did NOT edit my typo.

The typo was in the script from where these examples has been taken.

The problem was as SECONDS was created this way::

SECONDS=$(( $SECONDS1 + $SECONDS2 ))

But I had used seconds1 and seconds2 above in the related script.

SECONDS1 (seconds1) was build from the minutes of a time variable return (mp3 tag) (e.g. 03:47)

I just rebuilt minutes plus seconds to just seconds to have a <hscale> widget moving from the left to the right of the GUI to give an optical impression of current song position (I'd created my first Audio Player using GtkDialog; a simple one, just directory and files based).

So seconds1 is different to SECONDS1.

That's just all.

Probably Flash could just remove this topic?

_________________
RSH

T.O.P.L.E.S.S..

Das Schwert der Diffamierung ist stumpf geworden und der Schild der Ignoranz löchrig. Gut so! Cool Very Happy Laughing
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1149
Location: Japan

PostPosted: Thu 18 Feb 2016, 00:42    Post subject:  

I'm not much interested in your typo. I only wanted to draw your kind attention to the fact that $SECONDS is a special bash variable like $1, $LINENO or $PWD. You should never use these names for your own variables unless you know what you are doing.
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 1573
Location: Germany

PostPosted: Thu 18 Feb 2016, 02:38    Post subject:  

MochiMoppel wrote:
I'm not much interested in your typo. I only wanted to draw your kind attention to the fact that $SECONDS is a special bash variable like $1, $LINENO or $PWD. You should never use these names for your own variables unless you know what you are doing.

Ok, I did not know about $SECONDS being a special bash variable. Going to change this immediately.

Thanks.

_________________
RSH

T.O.P.L.E.S.S..

Das Schwert der Diffamierung ist stumpf geworden und der Schild der Ignoranz löchrig. Gut so! Cool Very Happy Laughing
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
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.0396s ][ Queries: 11 (0.0055s) ][ GZIP on ]