The only way I learned this stuff was by buying a bunch of books and reading them - often, more than once. Stuff on the web is too fragmentary to get the overall picture from.
At this point, your local library (I'm guessing you're old enough to remember what one of them is
), should have a bunch of books on Linux. Go for Linux for Dummies or a SAMS book to start with. The stuff from O'Reilly or academic publishers is best kept for later when you understand more.
Eventually, you'll probably want to buy a few so you can write in them and leave bookmarks.
In any case make notes of what you learn. I have a whole subdirectory tree on my computer: ~/public/howto which has more than a hundred little tutorials and notes I made for myself right after I figured out how to do something. I refer to it when I get stuck. I also have a much smaller directory elsewhere of working pieces of bash and other languages that I can refer to.
I don't keep all of this stuff in my head.
Here goes:
cat <<EOF | tee bla.txt
hello!
EOF
Create a "Here Document" (temporary file - stored in memory) containing everything starting on the next line and going until just before a line with just EOF on it.
(Advanced: Perform shell expansions on everything in that document - but there's nothing to do in this example.)
Assign that file to standard input (stdin).
Run the cat command which takes its input from a file, but if no argument is specified, it will use stdin (which is where we just put the contents of the here document) and copies it to stdout.
stdout gets redirected to stdin by the pipe (that's what simple pipes do).
run the command tee
(Advanced: not waiting for cat to finish. The whole pipeline runs at roughly the same time.)
which takes stdin and copies it to stdout while also copying it to the file bla.txt.
(Advanced: with no flags, the file bla.txt will be created if it does not already exist or truncated to zero length if it does exist - before copying the data to it. This happens before tee runs, so, even if tee died immediately, bla.txt would probably already be truncated. That's where I'm not sure of the exact details.)
Since this is the end of the pipeline, stdout will be copied to wherever the default is. If you are running this in a terminal, then the text will be displayed there. If not, the text may be thrown away - into /dev/null ...
(Advanced: when cat comes to the end of the here document, it will close the pipe and exit. tee will see this event and know that it has all the input and can terminate itself after closing bla.txt.
If instead of the here document, the input was from a very large or very slow source, it would be buffered into blocks by the file system. tee would get this input block by block rather than character by character. Depending on how things were setup, output from tee might be delayed until it got the next full block to work with.)
(Advanced, this script is a prime example of what is looked down upon and called a "useless cat". It uses cat and extra processes to do what the shell would do anyway. It would be better as:
tee bla.txt <<EOF
hello!
EOF
but then it wouldn't be a (bad) example of how to use a pipe.)
There are a couple of things to see here.
1) There's a whole lot more going on here than meets the eye.
As a beginner, you can pretty much ignore all the advanced stuff, but sooner or later it may bite you and you may end up scratching your head as to why code that looks perfectly good is doing something other than what you intended.
2) People who provide examples don't always know the best ways to do things.