intro-8.html

[ prev | next | top ]

## 8. Redirection

Apart from all the regular redirections like the Bourne shell has, zsh can do more. You can send the output of a command to more than one file, by specifying more redirections like

% echo Hello World >file1 >file2

and the text will end up in both files. Similarly, you can send the output to a file and into a pipe:

% make > make.log | grep Error

The same goes for input. You can make the input of a command come from more than one file.

% sort <file1 <file2 <file3

The command will first get the contents of file1 as its standard input, then those of file2 and finally the contents of file3. This, too, works with pipes.

% cut -d: -f1 /etc/passwd | sort <newnames

The sort will get as its standard input first the output of cut and then the contents of newnames.

Suppose you would like to watch the standard output of a command on your terminal, but want to pipe the standard error to another command. An easy way to do this in zsh is by redirecting the standard error using 2> >(...).

% find / -name games 2> >(grep -v ’Permission’ > realerrors)

The above redirection will actually be implemented with a regular pipe, not a temporary named pipe.

[ prev | next | top ]