The script is probably an example, and you are expected to change the
echo goodbye to do something more.
Let us assume that the script is called
demo. When you run it then as you have seen it first outputs "hello". It then sees if the output is going to the terminal or not, with the intention of deciding if you are running
demo | some other program
If it is the former then it just send the output of the rest of the file to the file called
log. If the latter then if creates a
named pipe and starts a
tee process to copy everything written to the named pipe to both the output of the
demo script (so
some other prog will get it) and to the file called
log. It then arranges to send the output of the rest of the file to this named pipe. It also arranges that when
demo finishes it will remove the named pipe.
exec 1>&- is not needed.
The net result of all of this is that the word "goodbye" is written to the file "log". If you ran
demo | cat you would see both "hello" and "goodbye" on your screen.
As @derobert points out in the comments, the named pipe has a predictable name. Depending on the setting of
umask this might allow someone to corrupt the output of
demo either by reading it (so
tee doesn't see it) or adding extra stuff for
tee to copy. This is in addition to a number of standard attacks that can be used against known or predicable names. Soft or hard links can be set up in advance to cause other files to be opened or truncated. On my linux system the mknod will fail if the file already exists, but as the script ignores this error then the
exec 1>$npipe will be executed.