Author |
Message |
LazY Puppy

Joined: 21 Nov 2014 Posts: 2007 Location: Germany
|
Posted: 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.
So this works of course also: STEPS=$(( $SECONDS * 60 ))
_________________ RSH
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0)
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! 
|
Back to top
|
|
 |
slavvo67
Joined: 12 Oct 2012 Posts: 1625 Location: The other Mr. 305
|
Posted: 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
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 2084 Location: Japan
|
Posted: 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
|
|
 |
LazY Puppy

Joined: 21 Nov 2014 Posts: 2007 Location: Germany
|
Posted: 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
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0)
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! 
|
Back to top
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 2084 Location: Japan
|
Posted: 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
|
|
 |
LazY Puppy

Joined: 21 Nov 2014 Posts: 2007 Location: Germany
|
Posted: 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
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0)
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! 
|
Back to top
|
|
 |
|