2

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?

4
  • 3
    Anything in alias | grep -i date? Commented Mar 29, 2012 at 11:48
  • What about locale? Does it work with LC_ALL=C date +...? Commented Mar 29, 2012 at 13:05
  • 2
    Gnnn. I've discovered the problem. I'll post an answer when SO lets me. Basically: Problem Exists Between Chair And Keyboard - or, to be more precise - problem exists in .bash_profile. Of course the clue is right there in the output - it's correctly outputting the date and the error message. Le sigh. Commented Mar 29, 2012 at 13:22
  • Indeed! .. I was about to ask why it printed correct output and then carped. Commented Mar 29, 2012 at 15:27

2 Answers 2

5

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:

date "%H:%M" # << the 1st stupid thing I did

… 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

date "+%R"

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

  1. Don't get distracted
  2. Follow a sequence
  3. Quit fiddling with your damned PS1 and do some real work for a change
Sign up to request clarification or add additional context in comments.

Comments

2

Works OK for me in OS X 10.6.8:

$ date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S"
DATE: 2012-03-29
TIME: 11:46:52
$

Are you using something other than the standard date that ships with OS X ?

$ which date
/bin/date
$

3 Comments

Nope, I'm using the same as you :/
The version of bash shouldn't matter; it's the version of date that's relevant. MacOS uses the BSD date command by default; here's the man page, which refers to strftime(3). It should work. The OP says in a comment he's found the problem; I'm not sure what it could be.
@Keith: good point - for some reason I thought that date was a bash built-in - my mistake - answer updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.