crontab中命令行中的百分号(%)需要做转义

844 views次阅读
没有评论
比如
我在crontab -e中用命令
echo -e “`date ‘+%s’`\t$RANDOM” > /tmp/xxx
的话
命令行直接用没有问题
但写在cron里的时候
‘%’需要转义成’\%’
原因还没找到
原因终于找到了
在linux下看crontab的帮助
man 5 crontab
里有这么一段:

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

大概意思是说
在cron文件的第六列,也就是命令列
百分号(%)被赋予了特殊含义
被看做是换行符,而且,其后面的内容被当做命令的标准输入
所以,要想正常使用百分号(%)的功能
需要在其前面添加转义符(\)

正文完
微信搜一搜“奇悦电脑科技”或扫描二维码关注我们
post-qrcode
 0
章郎虫
版权声明:本站原创文章,由 章郎虫 于2018-10-17发表,共计392字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。