%在crontab中有何特别之处? [英] How is % special in crontab?

查看:106
本文介绍了%在crontab中有何特别之处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在crontab中,您可以这样做吗?

In crontab, can you do something like this?

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

推荐答案

crontab行的实际问题不是$()或反引号.问题是百分号%.在crontabs中有特殊含义.

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.

从联机帮助页:

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

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

都可以在我的网站上工作.

both work on my site.

这篇关于%在crontab中有何特别之处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆