gpt4 book ai didi

shell - %(百分号)在 crontab 中有何特殊之处?

转载 作者:行者123 更新时间:2023-11-29 08:45:19 25 4
gpt4 key购买 nike

在crontab中,你能做这样的事情吗?

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

最佳答案

您的 crontab 行的实际问题不是 $() 或反引号。问题是百分号 %。它在 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.
...

如果您使用 \ 转义百分号,它应该会按预期工作:

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

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

两者都适用于我的网站。

关于shell - %(百分号)在 crontab 中有何特殊之处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5277508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com