Subject: Re: bug#15407: bug report
From: Eric Blake <[email-masked]>
To: João Marques <[email-masked]>
Cc: [email-masked]
Date: Wed, 18 Sep 2013 10:25:36 -0600
List-Id: <debbugs-submit.debbugs.gnu.org>

tag 15407 notabug
thanks

On 09/18/2013 07:07 AM, João Marques wrote:
> Hi good afternoon
> 
> Yesterday i was reading the manual (man date) of the date command and I
> think that the option + and ' isn't refer on it
> 
> so i was trying to make this command on a script:
> 
>  $(date +'%Y-%m-%d '%H:%M:%S')

As written, that's not a valid command, because it has unbalanced
quotes.  ' is not an option character seen by date, but a quoting
metacharacter consumed by the shell.  You may want to read a good manual
on shell quoting; but as a short tutorial, all of the following are
equivalent:

date +%y-%m-%d\ %H:%M:%S
date '+%y-%m-%d %H:%M:%S'
date '+'"%y-%m-%d"' '"%H:%M:%S"

and so on.  To see what the shell actually did with your quote
characters, use echo (and since the output of all three of these
commands is identical, you can understand why I claim that ' is not a
format character recognized by date):

echo date +%y-%m-%d\ %H:%M:%S
echo date '+%y-%m-%d %H:%M:%S'
echo date '+'"%y-%m-%d"' '"%H:%M:%S"

Why some people insist on using '' around most of the FORMAT argument,
but not the leading + portion (that is, why you see +'%y...' instead of
'+%y...' in examples), is beyond me, but it is perfectly valid shell
quoting either way.

> 
> maybe I'm wrong but if not, it was nice to include this information an some
> examples on the  manual
> so that anyone could make it more easily.

Meanwhile, the '+' option IS documented, in both the man and info pages.
 The man page starts out with:

SYNOPSIS
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

See, right there, the leading '+' is what designates a FORMAT argument.
 Failing to use a leading '+' is what tells date to interpret its
argument as MMDDhhmm instead of FORMAT.

Therefore, I'm closing this as not a bug, although you should feel free
to reply with any further questions.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org