0

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

date +3

outputs

3 

Other options like:

date -3

raise an error.

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

  • +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 '14 at 9:14
  • Why not? I like date +3%s3%Z3. – uprego Jan 23 '14 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 '14 at 10:22

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.