crontab 和 echo 的奇怪问题

aid*_*dan 0 linux ubuntu command-line-interface cron echo

$ echo -e "test1\ntest2" > logfile

$ echo -e "test1\ntest2" >> logfile

$ cat logfile
test1
test2
test1
test2

$ rm logfile

$ crontab -e
* * * * * echo -e "test1\ntest2" >> logfile

$ sleep 160

$ cat logfile
-e test1
test2
-e test1
test2
Run Code Online (Sandbox Code Playgroud)

为什么我-e在输出中得到 ?crontab 和 bash 都在使用/bin/echo

med*_*ina 8

他们可能不会同时使用/bin/echo. 使用的环境cron可能与您的交互式环境不同。指定完整路径以确保。

  • `type echo` 应该在这里为您提供一些清晰度:) (2认同)