How is % special in crontab?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 11:13:23

问题


In crontab, can you do something like this?

* * * * * echo $( date +%F) >> /path/date.txt

回答1:


The actual problem of your crontab line is not the $() or the backquotes. The problem is the percent sign %. It has a special meaning in crontabs.

From the manpage:

...
Percent-signs (%) in the command, unless escaped with backslash (\), 
will be changed into newline characters, and all data after the 
first % will be sent to the command  as standard input.
...

If you escape the percent sign with \ it should work as expected:

* * * * * echo $(date +\%F) >> /tmp/date.txt

or

* * * * * echo `date +\%F` >> /tmp/date2.txt

both work on my site.



来源:https://stackoverflow.com/questions/5277508/how-is-special-in-crontab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!