Short answer: >
must be followed by a filename or &n
(n is a number), and |
must be followed by another command invocation.
Details: In shell syntax, a call to some command contains several components. Example:
A=foo 2>/dev/null B=bar cmd arg1 arg2 >file 3>&4 arg3
Here, parameters 2>/dev/null
, >file
and 3>&4
are special parameters (containing an unescaped >
¹), they are used to establish io-redirections, and can appear anywhere in the command line. Filedesciptor 2 is redirected to /dev/null
, filedescriptor 1
(implicit) is redirected to file
and filedescriptor 3
is redirected to what filedescriptor 4 was linked to.
Then, among remaining parameters, A=foo
and B=bar
contain =
, so they are not considered as the command name: they give specific values to environment variables of the process to be launched.
Then comes the command cmd
and the real arguments: arg1
, arg2
, arg3
.
The pipe |
is not part of a command invocation, it links two such invocations together. Example:
CC=gcc make 2>&1 | LESS=--quit-at-eof less
Output on filedescriptor 1 by the first process will be received as input on filedescriptor 0 by the second process, through a “pipe” which acts like a buffer.
—
1. In fact, the special characters like >
are sometimes seen followed by a space. Even though this is allowed, the two (space-separated) strings must be understood as a single ‘entity’.
cat
keeps reading until it gets EOF. A pipe produces EOF on the output only when it gets EOF on the input. The logging daemon is opening the file, writing to it, and keeping it open — just like it does for a regular file — so EOF is never generated on the output. cat
just keeps reading, blocking whenever it exhausts what's currently in the pipe.
You can try this out yourself manually:
$ mkfifo test
$ cat test
And in another terminal:
$ cat > test
hello
There will be output in the other terminal. Then:
world
There will be more output in the other terminal. If you now Ctrl-D the input then the other cat
will terminate too.
In this case, the only observable difference between cat
and tail -f
will be if the logging daemon is terminated or restarted: cat
will stop permanently when the write end of the pipe is closed, but tail -f
will keep going (reopening the file) when the daemon is restarted.
Best Answer
There should be no difference. The
>>
will open the fifo with theO_APPEND
flag, and that shouldn't make any difference on a fifo or other non-seekable file.However, there are buggy interfaces like
sendfile(2)
in Linux, which do not work with files opened inO_APPEND
mode, and will object even to non-seekable files having that mode set, so you better always use the>
form.