Can anyone help me out with the following code snippet -
echo Start|cat>>log
When I tried
echo Start>>log
it gave the same output to the log file. Can anyone explain the difference between the two commands?
cat
is one of those programs that can take an argument and use it, or just use its standard input if you don't provide an argument. In other words, while:
cat xyzzy
will open the file xyzzy
and output its contents, the command:
cat
on its own will read its standard input and send that to standard output.
Hence piping some output through cat
without an argument is no different that just sending the output without cat
, other than creating a superfluous process. In other words, these two are functionally identical:
echo xyzzy | cat
echo xyzzy
You can use either but the latter (for both my example above and in your question) will use one less process and a few less keystrokes. The cat
filter on its own will simply pass the data through as-is and hence is not necessary.