Suppose note.txt contains one line that says Hello. What will these commands print?
cat note.txt | echo # a blank line
cat note.txt | echo Ready # Ready
The pipe (|) connects the output of cat to standard input (stdin), a stream the next command can read. Whether it reads that stream depends on the command. As Stéphane Chazelas puts it, “echo doesn't read its standard input.”1
echo prints its arguments, the words the shell passes to it on the command line, followed by a newline. In the first example, echo receives zero arguments, so all you see is the newline. In the second, it receives one argument, Ready.
The same rule explains echo < note.txt. The shell opens the file as standard input. The command still has zero arguments. Try changing just the command name to cat < note.txt. With no filenames of its own, cat reads standard input and prints Hello.
If you want to append that line to another file, let cat read it and use >> to send the output to the end of the destination file.2
cat note.txt >> journal.txt
Footnotes
-
Chazelas, S. (2013, February 4). Answer to “Redirecting the content of a file to the command ‘echo’”, para. 1. Unix & Linux Stack Exchange. ↩
-
Ankur. (2012, June 2). Answer to “Shell: read a file and echo it's contents to another file”. Stack Overflow. ↩