Let say we have a text file demo.txt that only contains the word 'demo' and a text file sample.txt that only contains the word 'sample'.
I understand that cat demo.txt >> sample.txt would append the contents of demo.txt into the contents of sample.txt.
But what happens when I have the cat command on both sides of the redirection symbol? I've tried the same thing with single and double redirection. I've studied enough to know that you really want to use the double redirection over the single if you don't want something overridden. I also know that the cat command is short for concatenation (it was a surprise to me that the 'cat' command can double as a txt print "function").
What is it that I'm not understanding about how this works that I feel cat demo.txt >> cat sample.txt should produce results?
catcommand is recognized? The second one is treated as a file. The shell thinks I've given it three files when I've really [tried] to give it two!Also, the fact that the order of the items doesn't matter is going to take some getting used to! I'm certainly not accustomed to such flexibility!
– noriloxic Apr 24 '22 at 21:41cattwo files (not three). The shell has used>>catas an instruction to redirect the output of thecatcommand into a file calledcat(appending the data). Note that in the very last command in my answer (<file.in cat >file.out),catis executed with no files as arguments. The input and output is handled by the shell, outside of the control of thecatcommand. – Kusalananda Apr 24 '22 at 21:47catin my directory, which I did not think to look for until you told me about a file calledcat! How does it know which file is the destination file for the append?catwas never meant to be a file.... I thought I was using a command/function. – noriloxic Apr 24 '22 at 21:53>or>>with a string likecator whatever other string, that string will be used as a filename (this is broadly true, without going into too complicated topics). Using>> catswould have created (or appended to) the file calledcats. There is no issue with having files called the same thing as commands. – Kusalananda Apr 24 '22 at 21:57type catto see ifcatis a program on your system and where -- on most it is/bin/cator/usr/bin/cat. Shell can run programs you create yourself, in files, in the same way(s) as system programs. – dave_thompson_085 Apr 25 '22 at 03:31