$ 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
Why am I getting the -e
in the output? Both crontab and bash are using /bin/echo
They're probably not both using
/bin/echo
. The environment used bycron
is probably different from your interactive environment. Specify the full path to be sure.This is one of the reasons people recommend using
printf
instead ofecho
for portability.The shell that
cron
uses issh
rather than Bash. On my system,sh
is really Dash and itsecho
doesn't have-e
. So-e
becomes just another string to be output. Other versions of the Bourne shell or shells that provide its functionality may have-e
.If you use
echo
without the full path in yourcrontab
, you're getting the shell's builtinecho
instead of/bin/echo
. On the command line, if you're using Bash, thenecho
without the full path gives you Bash's builtin version.