Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am on SunOS machine trying to get the date string of the past minute, yesterday I used this command I found on the internet

expr `date +%Y%m%d%k%M` - 1

which is worked just fine and I saw the output and this is the output I got from my session that is still opened:

bash-3.00$ expr `date +%Y%m%d%k%M` - 1
201303131641

Now I am trying to run this command on the same session and I got this output:

bash-3.00$ expr `date +%Y%m%d%k%M` - 1
expr: syntax error

My machine is running this OS:

bash-3.00$ uname -a
SunOS mySunOS 5.10 Generic_144488-11 sun4v sparc SUNW,Netra-T2000

I think there is some environmental variable or something that have been changed, can anyone help me out with this?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Try %H instead of %k. Yesterday it probably worked because the hour had double digits then. Note that this is not a good way to get the previous minute, because of what happens when the time is exactly on the hour.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.