Historical reason why date's %h and %b format codes produce the same output?

5

0

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.

pjd

Posted 2016-03-08T15:53:43.040

Reputation: 157

Indeed. %h seems the odder of those two choices. – wallyk – 2016-03-08T19:52:36.860

My guess is that there were originally two different implementations that used a different format code. For compatibility, both have been retained. – Barmar – 2016-03-08T20:42:53.050

Answers

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.

meatspace

Posted 2016-03-08T15:53:43.040

Reputation: 1 093

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 – 2016-05-31T20:00:15.420