Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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
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

Your Answer


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.