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

Are there any cons in using rounded corners for bar graphs?

Scam? Phone call from "Department of Social Security" asking me to call back

What was the intention with the Commodore 128?

Mind ya, it's Homophones Everywhere!

What are these panels underneath the wing root of a A380?

How does the Moon's gravity affect Earth's oceans despite Earth's stronger gravitational pull?

Unconventional examples of mathematical modelling

Good way to stop electrolyte tabs from turning into powder?

May the tower use the runway while an emergency aircraft is inbound?

Why does Japan use the same type of AC power outlet as the US?

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

Adding things to bunches of things vs multiplication

What are the advantages of this gold finger shape?

How to prevent criminal gangs from making/buying guns?

What is the question mark?

Is Fourier series a sampled version of Fourier transform?

Is there a fallacy about "appeal to 'big words'"?

If a person claims to know anything could it be disproven by saying 'prove that we are not in a simulation'?

Short comic about alien explorers visiting an abandoned world with giant statues that turn out to be alive but move very slowly

What would cause a nuclear power plant to break down after 2000 years, but not sooner?

Escape Velocity - Won't the orbital path just become larger with higher initial velocity?

Are there liquid fueled rocket boosters having coaxial fuel/oxidizer tanks?

What is a "soap"?

What modifiers are added to the attack and damage rolls of this unique longbow from Waterdeep: Dragon Heist?



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
    yesterday











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

    – JohnDoea
    yesterday


















-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
    yesterday











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

    – JohnDoea
    yesterday














-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 yesterday







JohnDoea

















asked yesterday









JohnDoeaJohnDoea

91 gold badge11 silver badges46 bronze badges




91 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
    yesterday











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

    – JohnDoea
    yesterday














  • 1





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

    – Sparhawk
    yesterday











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

    – JohnDoea
    yesterday








1




1





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

– Sparhawk
yesterday





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

– Sparhawk
yesterday













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

– JohnDoea
yesterday





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

– JohnDoea
yesterday










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
    yesterday











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

    – Kusalananda
    yesterday











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

    – ilkkachu
    yesterday











  • 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
    yesterday











  • 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
    yesterday














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
    yesterday











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

    – Kusalananda
    yesterday











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

    – ilkkachu
    yesterday











  • 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
    yesterday











  • 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
    yesterday
















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
    yesterday











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

    – Kusalananda
    yesterday











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

    – ilkkachu
    yesterday











  • 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
    yesterday











  • 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
    yesterday














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 yesterday

























answered yesterday









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
    yesterday











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

    – Kusalananda
    yesterday











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

    – ilkkachu
    yesterday











  • 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
    yesterday











  • 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
    yesterday



















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

    – ilkkachu
    yesterday











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

    – Kusalananda
    yesterday











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

    – ilkkachu
    yesterday











  • 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
    yesterday











  • 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
    yesterday

















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

– ilkkachu
yesterday





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

– ilkkachu
yesterday













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

– Kusalananda
yesterday





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

– Kusalananda
yesterday













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

– ilkkachu
yesterday





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

– ilkkachu
yesterday













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
yesterday





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
yesterday













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
yesterday





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
yesterday


















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...