Introducing UNIX and Linux |
Getting startedOverview |
Making copies of input and outputSuppose you have a command that displays something on your screen, and you wish to save it in a file. So far, we have discussed only how that output can be redirected to a file, so that in order to see it on the screen and save it in a file there are two possibilities. Firstly, you could run the command twice (the first time with no redirection, and then directed to a file). Secondly you initially run the command with output sent to a file and then view the file using a pager. Both methods involve duplicating the output to the command, firstly by producing it twice, and secondly by storing it and then viewing the stored output. The first method is no use if the command you run is
interactive, conducting a dialogue with you while it is
running. If you ran the command twice you might give it different
input each time, so the two outputs would probably differ. If your
command was time-sensitive, such as If you wish to make a copy in a file of the input to a command, there would also be a problem. If the command is interactive, so that we cannot store the input in an intermediate file, we have not yet met any mechanism at all which will perform this task. The solution is to use the command
This has the same effect as the command command_name on its own, except that a copy of all the standard input to the command is sent to copy_of_input (which will be overwritten if it already exists). Worked exampleSend user
To use Worked exampleRun the command
|
Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck