Is there a reason to use + or - in date arguments?How can I execute `date` inside of a cron tab job?Correct...

Airline power sockets shut down when I plug my computer in. How can I avoid that?

Programming a recursive formula into Mathematica and find the nth position in the sequence

Are there any OR challenges that are similar to kaggle's competitions?

Why is su world executable?

Earliest evidence of objects intended for future archaeologists?

Build a mob of suspiciously happy lenny faces ( ͡° ͜ʖ ͡°)

What does a comma signify in inorganic chemistry?

What's a good pattern to calculate a variable only when it is used the first time?

Output the list of musical notes

What's the point of writing that I know will never be used or read?

Is a suspension needed to do wheelies?

Can anybody tell me who this Pokemon is?

Is it alright to say good afternoon Sirs and Madams in a panel interview?

Designing a prison for a telekinetic race

Why should P.I be willing to write strong LOR even if that means losing a undergraduate from his/her lab?

Icon is not displayed in lwc

How to render "have ideas above his station" into German

My new Acer Aspire 7 doesn't have a Legacy Boot option, what can I do to get it?

When does The Truman Show take place?

Can planar set contain even many vertices of every unit equilateral triangle?

What is the purpose/function of this power inductor in parallel?

Do I need to start off my book by describing the character's "normal world"?

Trying to understand how Digital Certificates and CA are indeed secure

What happened after the end of the Truman Show?



Is there a reason to use + or - in date arguments?


How can I execute `date` inside of a cron tab job?Correct locking in shell scripts?How to schedule something run once using anacron?Is there a good reason to prevent users from using cron/at?How can I get at to work on OSX?Is there a reason to use “[ ! -f file ] || command” instead of “[ -f file ] && command”?Script to copy a file to a remote host and rename itCreate a script to check the date, time and string and trigger a mailReshaping json / reparing json inside shell script (remove trailing comma)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







-2















I use date +%F-%T to show date and time in this format: 2019-08-15-21:34:58.



From man date:




%F full date; same as %Y-%m-%d

%T time; same as %H:%M:%S




I recognized no explanation for + or -.



I later understood that the backslashes are escaping, the plus is arguments prefix and the hyphen is just a string-like separation (date-time),

and also, that some use the simpler +'%F-%T' or +"%F-%T" instead.



Is there a reason to use + or - in date arguments?










share|improve this question






















  • 1





    What happens if you run the command without the backslashes? It produces the same output on my system (date 8.31).

    – Sparhawk
    2 days ago











  • I remembered I tried it once and recall it worked the same. I understand it should work the same.

    – JohnDoea
    2 days ago


















-2















I use date +%F-%T to show date and time in this format: 2019-08-15-21:34:58.



From man date:




%F full date; same as %Y-%m-%d

%T time; same as %H:%M:%S




I recognized no explanation for + or -.



I later understood that the backslashes are escaping, the plus is arguments prefix and the hyphen is just a string-like separation (date-time),

and also, that some use the simpler +'%F-%T' or +"%F-%T" instead.



Is there a reason to use + or - in date arguments?










share|improve this question






















  • 1





    What happens if you run the command without the backslashes? It produces the same output on my system (date 8.31).

    – Sparhawk
    2 days ago











  • I remembered I tried it once and recall it worked the same. I understand it should work the same.

    – JohnDoea
    2 days ago














-2












-2








-2








I use date +%F-%T to show date and time in this format: 2019-08-15-21:34:58.



From man date:




%F full date; same as %Y-%m-%d

%T time; same as %H:%M:%S




I recognized no explanation for + or -.



I later understood that the backslashes are escaping, the plus is arguments prefix and the hyphen is just a string-like separation (date-time),

and also, that some use the simpler +'%F-%T' or +"%F-%T" instead.



Is there a reason to use + or - in date arguments?










share|improve this question
















I use date +%F-%T to show date and time in this format: 2019-08-15-21:34:58.



From man date:




%F full date; same as %Y-%m-%d

%T time; same as %H:%M:%S




I recognized no explanation for + or -.



I later understood that the backslashes are escaping, the plus is arguments prefix and the hyphen is just a string-like separation (date-time),

and also, that some use the simpler +'%F-%T' or +"%F-%T" instead.



Is there a reason to use + or - in date arguments?







shell-script cron syntax






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







JohnDoea

















asked 2 days ago









JohnDoeaJohnDoea

101 gold badge11 silver badges46 bronze badges




101 gold badge11 silver badges46 bronze badges











  • 1





    What happens if you run the command without the backslashes? It produces the same output on my system (date 8.31).

    – Sparhawk
    2 days ago











  • I remembered I tried it once and recall it worked the same. I understand it should work the same.

    – JohnDoea
    2 days ago














  • 1





    What happens if you run the command without the backslashes? It produces the same output on my system (date 8.31).

    – Sparhawk
    2 days ago











  • I remembered I tried it once and recall it worked the same. I understand it should work the same.

    – JohnDoea
    2 days ago








1




1





What happens if you run the command without the backslashes? It produces the same output on my system (date 8.31).

– Sparhawk
2 days ago





What happens if you run the command without the backslashes? It produces the same output on my system (date 8.31).

– Sparhawk
2 days ago













I remembered I tried it once and recall it worked the same. I understand it should work the same.

– JohnDoea
2 days ago





I remembered I tried it once and recall it worked the same. I understand it should work the same.

– JohnDoea
2 days ago










1 Answer
1






active

oldest

votes


















6














The backslashes do nothing.



The - and + characters do not need to be escaped, because they are not special in any way in the syntax of any shell.



$ set -o xtrace


$ date +%F-%T
+ date +%F-%T
2019-08-15-11:51:46


$ date +%F-%T
+ date +%F-%T
2019-08-15-11:51:50


As you can see in the above trace output, the command that gets executed by the shell is the same regardless of the backslashes. Note too that the trace output is only "debugging output" from the shell and that whatever commands it outputs generally are not suitable for shell input.



The + introduces a date format specification. And the - is just a literal dash, part of the format specification (will be a dash in the output too).



The command date +%F-%T is the same as date +%F-%T. You will often also see the date format quoted, as in date +'%F-%T'. This makes no difference here as the format is a single word, but in date +'%F %T' it needs to be quoted to keep the shell from splitting the format on the space into two separate arguments to date.



What does makes a difference is the % characters. You would want to escape these if you use them in a crontab specification. See e.g. How can I execute `date` inside of a cron tab job?



The % character was special in the syntax of the fish shell prior to version 3.0 (for job expansions) but only when the first character of a word (so not here when after a +). Similarly, in zsh, a leading % character is special in that a ? following it is not taken as a glob operator (to allow things like kill %?cmd without having to quote the ?), but again that doesn't apply here.






share|improve this answer




























  • For some reason though, Busybox's shell escapes the plus-sign when tab-completing.

    – ilkkachu
    2 days ago











  • @ilkkachu Not for me in that shell. What are you completing?

    – Kusalananda
    2 days ago











  • just filenames. Actually it seems to escape about everything that's not a-z0-9_-, so it's probably just being careful, dunno.

    – ilkkachu
    2 days ago











  • Note that in the rc or akanga shells, backslash is not special, so date +%T would be different from date +%T there (the latter being treated the same as date '+%T' and so causing a syntax error by date)

    – Stéphane Chazelas
    2 days ago











  • Note that some shells' xtrace do not output code which when reinput would produce the same outcome, and some could preserve the quoting from the input. So you may want to clarify that your test output there is run from bash or any other shell that behaves in a similar way.

    – Stéphane Chazelas
    2 days ago














Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f535710%2fis-there-a-reason-to-use-or-in-date-arguments%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














The backslashes do nothing.



The - and + characters do not need to be escaped, because they are not special in any way in the syntax of any shell.



$ set -o xtrace


$ date +%F-%T
+ date +%F-%T
2019-08-15-11:51:46


$ date +%F-%T
+ date +%F-%T
2019-08-15-11:51:50


As you can see in the above trace output, the command that gets executed by the shell is the same regardless of the backslashes. Note too that the trace output is only "debugging output" from the shell and that whatever commands it outputs generally are not suitable for shell input.



The + introduces a date format specification. And the - is just a literal dash, part of the format specification (will be a dash in the output too).



The command date +%F-%T is the same as date +%F-%T. You will often also see the date format quoted, as in date +'%F-%T'. This makes no difference here as the format is a single word, but in date +'%F %T' it needs to be quoted to keep the shell from splitting the format on the space into two separate arguments to date.



What does makes a difference is the % characters. You would want to escape these if you use them in a crontab specification. See e.g. How can I execute `date` inside of a cron tab job?



The % character was special in the syntax of the fish shell prior to version 3.0 (for job expansions) but only when the first character of a word (so not here when after a +). Similarly, in zsh, a leading % character is special in that a ? following it is not taken as a glob operator (to allow things like kill %?cmd without having to quote the ?), but again that doesn't apply here.






share|improve this answer




























  • For some reason though, Busybox's shell escapes the plus-sign when tab-completing.

    – ilkkachu
    2 days ago











  • @ilkkachu Not for me in that shell. What are you completing?

    – Kusalananda
    2 days ago











  • just filenames. Actually it seems to escape about everything that's not a-z0-9_-, so it's probably just being careful, dunno.

    – ilkkachu
    2 days ago











  • Note that in the rc or akanga shells, backslash is not special, so date +%T would be different from date +%T there (the latter being treated the same as date '+%T' and so causing a syntax error by date)

    – Stéphane Chazelas
    2 days ago











  • Note that some shells' xtrace do not output code which when reinput would produce the same outcome, and some could preserve the quoting from the input. So you may want to clarify that your test output there is run from bash or any other shell that behaves in a similar way.

    – Stéphane Chazelas
    2 days ago
















6














The backslashes do nothing.



The - and + characters do not need to be escaped, because they are not special in any way in the syntax of any shell.



$ set -o xtrace


$ date +%F-%T
+ date +%F-%T
2019-08-15-11:51:46


$ date +%F-%T
+ date +%F-%T
2019-08-15-11:51:50


As you can see in the above trace output, the command that gets executed by the shell is the same regardless of the backslashes. Note too that the trace output is only "debugging output" from the shell and that whatever commands it outputs generally are not suitable for shell input.



The + introduces a date format specification. And the - is just a literal dash, part of the format specification (will be a dash in the output too).



The command date +%F-%T is the same as date +%F-%T. You will often also see the date format quoted, as in date +'%F-%T'. This makes no difference here as the format is a single word, but in date +'%F %T' it needs to be quoted to keep the shell from splitting the format on the space into two separate arguments to date.



What does makes a difference is the % characters. You would want to escape these if you use them in a crontab specification. See e.g. How can I execute `date` inside of a cron tab job?



The % character was special in the syntax of the fish shell prior to version 3.0 (for job expansions) but only when the first character of a word (so not here when after a +). Similarly, in zsh, a leading % character is special in that a ? following it is not taken as a glob operator (to allow things like kill %?cmd without having to quote the ?), but again that doesn't apply here.






share|improve this answer




























  • For some reason though, Busybox's shell escapes the plus-sign when tab-completing.

    – ilkkachu
    2 days ago











  • @ilkkachu Not for me in that shell. What are you completing?

    – Kusalananda
    2 days ago











  • just filenames. Actually it seems to escape about everything that's not a-z0-9_-, so it's probably just being careful, dunno.

    – ilkkachu
    2 days ago











  • Note that in the rc or akanga shells, backslash is not special, so date +%T would be different from date +%T there (the latter being treated the same as date '+%T' and so causing a syntax error by date)

    – Stéphane Chazelas
    2 days ago











  • Note that some shells' xtrace do not output code which when reinput would produce the same outcome, and some could preserve the quoting from the input. So you may want to clarify that your test output there is run from bash or any other shell that behaves in a similar way.

    – Stéphane Chazelas
    2 days ago














6












6








6







The backslashes do nothing.



The - and + characters do not need to be escaped, because they are not special in any way in the syntax of any shell.



$ set -o xtrace


$ date +%F-%T
+ date +%F-%T
2019-08-15-11:51:46


$ date +%F-%T
+ date +%F-%T
2019-08-15-11:51:50


As you can see in the above trace output, the command that gets executed by the shell is the same regardless of the backslashes. Note too that the trace output is only "debugging output" from the shell and that whatever commands it outputs generally are not suitable for shell input.



The + introduces a date format specification. And the - is just a literal dash, part of the format specification (will be a dash in the output too).



The command date +%F-%T is the same as date +%F-%T. You will often also see the date format quoted, as in date +'%F-%T'. This makes no difference here as the format is a single word, but in date +'%F %T' it needs to be quoted to keep the shell from splitting the format on the space into two separate arguments to date.



What does makes a difference is the % characters. You would want to escape these if you use them in a crontab specification. See e.g. How can I execute `date` inside of a cron tab job?



The % character was special in the syntax of the fish shell prior to version 3.0 (for job expansions) but only when the first character of a word (so not here when after a +). Similarly, in zsh, a leading % character is special in that a ? following it is not taken as a glob operator (to allow things like kill %?cmd without having to quote the ?), but again that doesn't apply here.






share|improve this answer















The backslashes do nothing.



The - and + characters do not need to be escaped, because they are not special in any way in the syntax of any shell.



$ set -o xtrace


$ date +%F-%T
+ date +%F-%T
2019-08-15-11:51:46


$ date +%F-%T
+ date +%F-%T
2019-08-15-11:51:50


As you can see in the above trace output, the command that gets executed by the shell is the same regardless of the backslashes. Note too that the trace output is only "debugging output" from the shell and that whatever commands it outputs generally are not suitable for shell input.



The + introduces a date format specification. And the - is just a literal dash, part of the format specification (will be a dash in the output too).



The command date +%F-%T is the same as date +%F-%T. You will often also see the date format quoted, as in date +'%F-%T'. This makes no difference here as the format is a single word, but in date +'%F %T' it needs to be quoted to keep the shell from splitting the format on the space into two separate arguments to date.



What does makes a difference is the % characters. You would want to escape these if you use them in a crontab specification. See e.g. How can I execute `date` inside of a cron tab job?



The % character was special in the syntax of the fish shell prior to version 3.0 (for job expansions) but only when the first character of a word (so not here when after a +). Similarly, in zsh, a leading % character is special in that a ? following it is not taken as a glob operator (to allow things like kill %?cmd without having to quote the ?), but again that doesn't apply here.







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









KusalanandaKusalananda

160k18 gold badges316 silver badges502 bronze badges




160k18 gold badges316 silver badges502 bronze badges
















  • For some reason though, Busybox's shell escapes the plus-sign when tab-completing.

    – ilkkachu
    2 days ago











  • @ilkkachu Not for me in that shell. What are you completing?

    – Kusalananda
    2 days ago











  • just filenames. Actually it seems to escape about everything that's not a-z0-9_-, so it's probably just being careful, dunno.

    – ilkkachu
    2 days ago











  • Note that in the rc or akanga shells, backslash is not special, so date +%T would be different from date +%T there (the latter being treated the same as date '+%T' and so causing a syntax error by date)

    – Stéphane Chazelas
    2 days ago











  • Note that some shells' xtrace do not output code which when reinput would produce the same outcome, and some could preserve the quoting from the input. So you may want to clarify that your test output there is run from bash or any other shell that behaves in a similar way.

    – Stéphane Chazelas
    2 days ago



















  • For some reason though, Busybox's shell escapes the plus-sign when tab-completing.

    – ilkkachu
    2 days ago











  • @ilkkachu Not for me in that shell. What are you completing?

    – Kusalananda
    2 days ago











  • just filenames. Actually it seems to escape about everything that's not a-z0-9_-, so it's probably just being careful, dunno.

    – ilkkachu
    2 days ago











  • Note that in the rc or akanga shells, backslash is not special, so date +%T would be different from date +%T there (the latter being treated the same as date '+%T' and so causing a syntax error by date)

    – Stéphane Chazelas
    2 days ago











  • Note that some shells' xtrace do not output code which when reinput would produce the same outcome, and some could preserve the quoting from the input. So you may want to clarify that your test output there is run from bash or any other shell that behaves in a similar way.

    – Stéphane Chazelas
    2 days ago

















For some reason though, Busybox's shell escapes the plus-sign when tab-completing.

– ilkkachu
2 days ago





For some reason though, Busybox's shell escapes the plus-sign when tab-completing.

– ilkkachu
2 days ago













@ilkkachu Not for me in that shell. What are you completing?

– Kusalananda
2 days ago





@ilkkachu Not for me in that shell. What are you completing?

– Kusalananda
2 days ago













just filenames. Actually it seems to escape about everything that's not a-z0-9_-, so it's probably just being careful, dunno.

– ilkkachu
2 days ago





just filenames. Actually it seems to escape about everything that's not a-z0-9_-, so it's probably just being careful, dunno.

– ilkkachu
2 days ago













Note that in the rc or akanga shells, backslash is not special, so date +%T would be different from date +%T there (the latter being treated the same as date '+%T' and so causing a syntax error by date)

– Stéphane Chazelas
2 days ago





Note that in the rc or akanga shells, backslash is not special, so date +%T would be different from date +%T there (the latter being treated the same as date '+%T' and so causing a syntax error by date)

– Stéphane Chazelas
2 days ago













Note that some shells' xtrace do not output code which when reinput would produce the same outcome, and some could preserve the quoting from the input. So you may want to clarify that your test output there is run from bash or any other shell that behaves in a similar way.

– Stéphane Chazelas
2 days ago





Note that some shells' xtrace do not output code which when reinput would produce the same outcome, and some could preserve the quoting from the input. So you may want to clarify that your test output there is run from bash or any other shell that behaves in a similar way.

– Stéphane Chazelas
2 days ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f535710%2fis-there-a-reason-to-use-or-in-date-arguments%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...