5

Is there a historical reason why date's %h and %b format codes produce the same output?

$ echo $(date +\%h)
Mar

$ echo $(date +\%b)
Mar

Other redundancies exist in date format codes as well, but this one caught my attention this morning. See also this page.

  • Indeed. %h seems the odder of those two choices. – wallyk Mar 8 '16 at 19:52
  • My guess is that there were originally two different implementations that used a different format code. For compatibility, both have been retained. – Barmar Mar 8 '16 at 20:42
1

According to http://linux.die.net/man/3/strftime, %h is in the Single UNIX Specification (denoted by 'SU' below) but %b is not.

%b
The abbreviated month name according to the current locale.

%h
Equivalent to %b. (SU)

That's the only difference I can find. man date/strptime/strftime don't contain this information.

  • This is good. Thanks. Reading further on that page I found the rest of the answer. The date function contains these redundancies to conform to various standards. Specific to my question, %b conforms to the ANSI C standard, while, as you noted, %h conforms to the Single UNIX Specification. Thus, for compatibility with various standards, redundancies exist. Additional standards that the various encodings conform to are SVr4, C89, C99, Olson's timezone package, glibc, glibc2, POSIX.1, and POSIX.2. In conjunction with my comment here, I'll give you the checkmark. – pjd May 31 '16 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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