start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 13.12 Writing to Multiple Terminals for Demonstrations Chapter 13
Redirecting Input and Output
Next: 13.14 What Can You Do with an Empty File?
 

13.13 The "Filename" -

If you put filenames on the command line, a typical UNIX command will read those files. With no filenames, the command will read its standard input. How can you make the command read both files and standard input? Some UNIX systems, and utilities such as gawk (33.12), support a special name like /dev/stdin (13.1). Some older UNIX commands, like cat (25.2) and diff (28.1), will accept a "filename" of - (dash). There's not actually a file named -; it's just a shorthand for "read standard input."

NOTE: This syntax might change in the future.

For instance, here's how to compare two files on different computers. The rsh snooze cat bin/aprog command sends a copy of the file bin/aprog from the remote host snooze down the pipe here on the local computer. diff compares the local file aprog.new to the standard input from the pipe:

rsh 
% rsh snooze cat bin/aprog | diff - aprog.new

For more examples, see articles 9.11 and 13.7.

- JP


Previous: 13.12 Writing to Multiple Terminals for Demonstrations UNIX Power ToolsNext: 13.14 What Can You Do with an Empty File?
13.12 Writing to Multiple Terminals for Demonstrations Book Index13.14 What Can You Do with an Empty File?

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System