Difference between cat and echo

Sjoerd Mullender sjoerd at acm.org
Fri Apr 13 16:07:27 UTC 2007


Dan Track wrote:
> Hi
> 
> I've been testing something out in cron, I ran the following:
> 
> MAILTO: user at example.com
> * * * * * cat % This is a test message
> * * * * * echo % This is a test message
> 
> When I get my emails, for the cat command, the subject states: "cat "
> and the body states:
> "This is a test message"
> 
> However for the echo command I get "echo " in the subject but the body
> is empty.
> 
> This made me wonder and hence ask you guys, why does cat work in
> outputting the message while echo doesn't?
> 
> Thanks in advance for any help.
> 
> Dan
> 

RTF(riendly)M.  In this case, "man 5 crontab" is an excellent start.  It
says:

The  "sixth"  field  (the rest of the line) specifies the command to be
run.  The entire command portion of the line, up  to  a  newline  or  %
character, will be executed by /bin/sh or by the shell specified in the
SHELL variable of the cronfile.   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.

Which means that in your case both cat and echo get that string as
input, but only cat reads from standard input.

-- 
Sjoerd Mullender

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 369 bytes
Desc: OpenPGP digital signature
Url : http://lists.fedoraproject.org/pipermail/users/attachments/20070413/9b59d697/attachment-0002.bin 


More information about the users mailing list