0

Yes, this is a minor issue, but I wonder why

date +3

outputs

3 

Other options like:

date -3

raise an error.

6
  • But what were you trying to accomplish anyway?
    – 41754
    Jan 23, 2014 at 9:11
  • Return the n day from today. Jan 23, 2014 at 9:23
  • That is done with date -d"@$(($(date +%s) + $((3 * 24 * 3600))))". You did not ask the correct question.
    – 41754
    Jan 23, 2014 at 9:30
  • Well, I asked what I wanted to know: why this way went wrong. Jan 23, 2014 at 9:32
  • I wanted to learn how to do it so much :D.
    – 41754
    Jan 23, 2014 at 9:45

1 Answer 1

4

Because the plus glyph is a format specifier.

In general, in UNIX programs, arguments with a minus glyph are options for the program and arguments with a plus glyph are commands for the program (see man less).

Manual page man date shows more information on this topic.

3
  • +1 But: The generalization (options vs. commands) does not apply here, since date is never interactive. Also + is NOT a format specifier, it indicates the start of a parameter string (this string then contains format specifiers, but + is not one of them) The relevance of + is indicated in the man page synopsis, date [OPTION]... [+FORMAT], "FORMAT" being the format string. Of course, this still doesn't explain why date +3 spits out 3...it should be an error.
    – goldilocks
    Jan 23, 2014 at 9:14
  • Why not? I like date +3%s3%Z3.
    – 41754
    Jan 23, 2014 at 9:26
  • Hmmm, good point. date +"**"%s"**"%Z works too. Kind of un- or very ambiguously documented unless you read the info coreutils stuff tho.
    – goldilocks
    Jan 23, 2014 at 10:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .