Link to home
Start Free TrialLog in
Avatar of TwentyFourSeven
TwentyFourSeven

asked on

Mod calculations and "bad number "

MINUTE=`date +"%M"`
MINUTE_MOD=$((MINUTE%15))
]

Open in new window


Most of the time, the above works nicely.

Until you get to the start of the hour.....

08: bad number `08'
09: bad number `09'


Where am I going wrong ?
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Hi,
which shell dou you actually use? I assume it's not really bsh, or is it?
With bash your script should work fine, but if not I think getting rid of the leading zero could help -
MINUTE=`date +"%M"`
MINUTE=$[MINUTE##0}
MINUTE_MOD=$((MINUTE%15))
 With bsh you should do
MINUTE=`date +"%M"`
MINUTE_MOD=`expr MINUTE % 15`
wmp

 
Avatar of TwentyFourSeven
TwentyFourSeven

ASKER

>> which shell dou you actually use? I assume it's not really bsh, or is it?

#!/bin/sh
/bin/sh is in most cases a  (hard-) link to the system's default shell.
I assume /bin/sh and /bin/bash are of exactly the same size?
Btw. I hit the wrong key here, sorry -
MINUTE=${MINUTE##0}
 
$ ls -la /bin/sh
-r-xr-xr-x  3 root  bin  336632 Mar 18 02:32 /bin/sh
$ openssl sha1 /bin/sh
SHA1(/bin/sh)= f9e4cef44ea02c0ce944ea530dae0a344e64de23
$ openssl sha1 /bin/bash
/bin/bash: No such file or directory
(Underlying OS is OpenBSD)
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah..... OpenBSD is fun.... ;-)


$ cat test.sh                                                                                                                                                                                                   
#!/bin/sh

MINUTE=`date +"%M"` 
MINUTE=$[MINUTE##0}
MINUTE_MOD=$((MINUTE%15))


echo $MINUTE_MOD

$ sh test.sh                                                                                                                                                                                                    
test.sh[5]: $[MINUTE##0}: unexpected `$'

Open in new window

Yep, that's due to my typo, which I corrected subsequently ...
MINUTE=${MINUTE##0}
oops..... sorry about that !

That works.

Give me 10 minutes or so until we get to the new hour for it to test ;-)