Weird result with Bash's printf '%(%F %T)T'

How do you explain this? Is it a bug or did I overlook something?


printf '%(%F %T)T\n' 0 -1 -2 -3
1970-01-01 00:00:00
2023-08-16 19:31:33
2023-08-14 22:56:58
1969-12-31 23:59:57

>Solution :

Only -1 and -2 are defined. From man bash:

%(datefmt)T: causes printf to output the date-time string resulting from using datefmt as a format string for strftime(3). The corresponding argument is an integer representing the number of seconds since the epoch. Two special argument values may
be used: -1 represents the current time, and -2 represents the time the shell was invoked. If no argument is specified, conversion behaves as if -1 had been given. This is an exception to the usual printf behavior.

Leave a Reply