Weird problem with output from "date '+3600*%H+60*%M+%S' "

Hi,

I came across a script a few months ago that allowed you to use the following script to include the current time into your prompt (useful from auditting purposes):

# Set Prompt
typeset -RZ2 _x1 _x2 _x3
let SECONDS=$(date '+3600*%H+60*%M+%S')
_s='(_x1=(SECONDS/3600)%24)==(_x2=(SECONDS/60)%60)==(_x3=SECONDS%60)'
TIME='"${_d[_s]}$_x1:$_x2"'
export PS1=${TIME}'${ME}:${PWD}:[$QM]# '

I've just noticed a really wierd problem on one server I'm using this on which is, if the time is before 10:00 an error occurs and the prompt is set to how many minutes you've been logged on. Logging on before 10:00 I get messages like this (the numbers change depending on the time:

09+60*53+48: 0403-009 The specified number is not valid for this command.
or
09+60*59+31: 0403-009 The specified number is not valid for this command.

After 10:00 this code works fine.

Anyone know what the problem might be?

Gareth

Posix, in their wisdom has decreed that a number starting with a leading zero is to be interpreted as an octal number. So in a posix compliant shell, 09 is illegal. :rolleyes:

Thanks for this info.

Is there any way to adjust the script so any leading zero is removed?

Gareth

Try forcing base 10:
let SECONDS=$(date '+3600*10#%H+60*10#%M+10#%S')

Thanks, that worked. What's confusing me is why this script works in its original form before 10am on some servers but not on others. What should I check to see what's different between these servers and how do I check that?

Thanks

Dave Korn did not possess the wisdom of Posix and he forgot to make integers with a leading 0 to be interpreted as octal. Thank goodness Posix came along to pick up the slack! Some of your systems still have a non-posix compliant korn shell and are willing to perform arithmetic on an integer like 08 and 09. A test? Just run the script in the original form prior to 10am.