TwentyFourSeven
asked on
Mod calculations and "bad number "
MINUTE=`date +"%M"`
MINUTE_MOD=$((MINUTE%15))
]
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 ?
ASKER
>> which shell dou you actually use? I assume it's not really bsh, or is it?
#!/bin/sh
#!/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}
I assume /bin/sh and /bin/bash are of exactly the same size?
Btw. I hit the wrong key here, sorry -
MINUTE=${MINUTE##0}
ASKER
$ 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)= f9e4cef44ea02c0ce944ea530d ae0a344e64 de23
$ openssl sha1 /bin/bash
/bin/bash: No such file or directory
-r-xr-xr-x 3 root bin 336632 Mar 18 02:32 /bin/sh
$ openssl sha1 /bin/sh
SHA1(/bin/sh)= f9e4cef44ea02c0ce944ea530d
$ openssl sha1 /bin/bash
/bin/bash: No such file or directory
ASKER
(Underlying OS is OpenBSD)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 `$'
Yep, that's due to my typo, which I corrected subsequently ...
MINUTE=${MINUTE##0}
MINUTE=${MINUTE##0}
ASKER
oops..... sorry about that !
That works.
Give me 10 minutes or so until we get to the new hour for it to test ;-)
That works.
Give me 10 minutes or so until we get to the new hour for it to test ;-)
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