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 ))
Division, Addition, Subtraction and Multiplication
- LazY Puppy
- Posts: 1934
- Joined: Fri 21 Nov 2014, 18:14
- Location: Germany
Division, Addition, Subtraction and Multiplication
RSH
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:
Maybe this link will help. Different format but it appears to work.
http://www.murga-linux.com/puppy/viewtopic.php?t=101416
http://www.murga-linux.com/puppy/viewtopic.php?t=101416
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Re: Division, Addition, Subtraction and Multiplication
Why not?LazY Puppy wrote:This won't work: 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.So this works of course also: STEPS=$(( $SECONDS * 60 ))
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: Select all
#!/bin/bash
SECONDS=2
sleep 3
STEP=$(( $SECONDS * 60 ))
echo $STEP
- LazY Puppy
- Posts: 1934
- Joined: Fri 21 Nov 2014, 18:14
- Location: Germany
Re: Division, Addition, Subtraction and Multiplication
No, I did NOT edit my typo.MochiMoppel wrote:Why not?LazY Puppy wrote:This won't work: 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.So this works of course also: STEPS=$(( $SECONDS * 60 ))
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: Select all
#!/bin/bash SECONDS=2 sleep 3 STEP=$(( $SECONDS * 60 )) echo $STEP
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) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
- LazY Puppy
- Posts: 1934
- Joined: Fri 21 Nov 2014, 18:14
- Location: Germany
Ok, I did not know about $SECONDS being a special bash variable. Going to change this immediately.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.
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) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink: