tailieunhanh - Redirecting I/O

This chapter generally doesn’t apply to full-screen programs, such as the Pico editor, that take control of your whole terminal window. (The pager pr ograms, less, more, and pg, do work together in this way.) It also doesn’t apply to graphical programs, such as StarOffice or Netscape, that open their own windows on your screen. | In this chapter Standard Input and Standard Output Pipes and Filters 5 Redirecting I O Many Unix programs read input such as a file and write output. In this chapter we discuss Unix programs that handle their input and output in a standard way. This lets them work with each other. This chapter generally doesn t apply to full-screen programs such as the Pico editor that take control of your whole terminal window. The pager programs less more and pg do work together in this way. It also doesn t apply to graphical programs such as StarOffice or Netscape that open their own windows on your screen. Standard Input and Standard Output What happens if you don t give a filename argument on a command line Most programs will take their input from your keyboard instead after you press the first RETURN to start the program running that is . Your terminal keyboard is the program s standard input. As a program runs the results are usually displayed on your terminal screen. The terminal screen is the program s standard output. So by default each of these programs takes its input from the standard input and sends the results to the standard output. These two default cases of input output I O can be varied. This is called I O redirection. If a program doesn t normally read from files but reads from its standard input you can give a filename by using the less-than symbol operator. 87 7 January 2002 13 13 88 Chapter 5 Redirecting I O For example the mail program see the section Sending Mail from a Shell Prompt in Chapter 6 normally reads the message to send from your keyboard. Here s how to use the input redirection operator to mail the contents of the file to_do to bigboss@. mail bigboss@ to_do If a program writes to its standard output which is normally the screen you can make it write to a file instead by using the greater-than symbol operator. The pipe operator sends the standard output of one program to the standard input of another program. Input output .

TỪ KHÓA LIÊN QUAN