I’m unable to use date (under OS X 10.6, using bash) without getting the following “illegal time format” error:
$ date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S"
DATE: 2012-03-29
TIME: 11:39:30
date: illegal time format
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
I’m taking that example direct from the man page. What am I doing wrong?
So – this is an illustration of stupidity. Not interested in how stupidity ends up on Stack Overflow? Stop reading.
I was trying to add time to my prompt. Rather than relying on \t, I wanted to use date (I have a prompt file that is used across shells). Full of confidence (and who wouldn’t be – it’s just date, right? It’s not like I’m trying to configure sendmail or anything), I added this to my PS1:
… then switched to my prompt. At this point I suddenly thought “I’m sure there’s a shorthand for %H:%M”, and called up the manpage.
Then I reloaded my profile (not noticing the error I got – the 2nd stupid thing I did) and typed
… and obviously got both the output of date, and the error. Cue half an hour of me mashing my face into the desk and asking SO for help while the answer was right in front of me – the output of date and the error. I’d managed in the space of about 20 seconds to completely forget I’d added anything to my .bash_profile.
Beggars belief.
My lessons from this: