DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Commands revisited: pipes and redirection

Using a file as input to a command

Just as you can redirect the output of a command, you can redirect the input of a command. To tell a command to take input from a file, you type the command, then a less-than sign (<), then the file that you want it to use as input. The file used for input is still there after the command is finished; it is only read, it is not overwritten.

Suppose, for example, you wanted to mail a file called report to Doug you could type mail doug < report

This tells the mail command to take its input from report. This is a very fast way of mailing things because you never enter the interactive mail program, you just send the file.

Try mailing yourself a copy of /usr/adm/messages, the file that stores system startup messages, using input redirection:

  1. Type mail loginname < /usr/adm/messages and press <Enter>. (Substitute your own login name for loginname.)

  2. Confirm that the file was sent by typing mail and pressing <Enter>. Read your current messages; one of these contains the startup messages file.

  3. Type q to quit mail.

Q: If I use redirection to mail a file to someone without entering the mail program, is there any way I can get a subject header on the message?

A: You can get a subject header on the file by using the -s "subject" option to mail. For example, to mail the file prognotes to Anne, you could type:

mail -s "Program notes" anne < prognotes

This sends the file with the subject heading ``Program notes.'' For more information about mail options, see mail(C).


Next topic: Joining files together
Previous topic: Putting the output of a command into a file

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003