bash /bin/sh: 1: 语法错误:反引号替换中的 EOF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42241371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
/bin/sh: 1: Syntax error: EOF in backquote substitution
提问by Vicky
I created a new task in crontab as shown below :
我在 crontab 中创建了一个新任务,如下所示:
*/2 * * * * mongodump --db prodys --out /backup/databases/mongoDatabases/`date +"%m-%d-%y"`
I'm getting following error :
我收到以下错误:
/bin/sh: 1: Syntax error: EOF in backquote substitution
Please help, I don't have any clue whats wrong.
请帮忙,我不知道出了什么问题。
回答by Inian
The problem is that cron
treats %
as newlines. From crontab POSIX man
page:
问题是它被cron
视为%
换行符。从crontab POSIX man
页面:
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.
命令中的百分号 (%) 除非用反斜杠 \ 转义,否则将更改为换行符,并且第一个 % 之后的所有数据将作为标准输入发送到命令。
Also use Command Substitutionsyntax as $()
over the legacy `` syntax as
还使用命令替换语法作为$()
传统的 `` 语法作为
You could change your command to something like,
您可以将命令更改为类似的内容,
*/2 * * * * mongodump --db prodys --out /backup/databases/mongoDatabases/$(date +'\%m-\%d-\%y')