UNIX Notes

Wednesday, June 17, 1998

pipe



who | wc -l
As soon as the first byte leaves Process A, Process B forks and runs psuedosimutaneously, something that causes processes super fast. Can be used to create reglrg processes provided that filters are used.

  • A filter reads from standard in and writes to standard out.


The following illustration is a DOSSY way of using the "more" command:

If a process reads from stdin but doesn't write to stdout, that process can only be used as the last process in a pipe.

If a process doesn't read from stdin but writes to stdout, that process can only be used as the first process in a pipe.

The pipe output is the result of the last process.

tee

A tee in a pipe gives you intermediate results. Good for debugging pipes.

who | tee | whoson | wc -l | wc -l

A tee is one way to redirect stdout.

Redirection of stdout
who | wc -w > whoto

Try this:
who > wed617
who > finger > wed617
If you were to cat wed617 now, what would be the contents? Answer: finger results. The > rewrites the entire file, writing over any and all data that was already in the existing file.

When a file is the target of a redirection, the first thing that happens is the next byte pointer is set to 0 (effectively emptying the file.)

sort myfile > myfile

First, the NBP is set to 0. Then, sort sorts myfile (extremely quickly, for myfile is now empty!)

Redirection of stdin

tr < myfile

(Redirection probably won't be used often in this class.)
Redirection of stderr

This process works differently in sh and csh.

csh is easy to do: