Debian GNU/Linux : Guide to Installation and Usage by John Goerzen;Ossama Othman
page 102 of 298 (34%)
page 102 of 298 (34%)
![]() | ![]() |
|
When you run a program from the shell, usually standard input comes from your keyboard, and standard output and error both go to your screen. However, you can ask the shell to change these defaults. For example, the echo command sends it output to standard output, normally the screen. But you can send it to a file instead with the output redirection operator, >. For example, to put the word ``Hello'' in the file myfile, use this command: echo Hello > myfile Use cat or your text file pager (more or less) to view myfile's contents; see Figure 6.3 on page [*]. Figure 6.3: Redirecting output \begin{figure}\par\par\begin{list}{}{ \setlength{\rightmargin}{\leftmargin} \ra... ...llo~>~myfile} \par\$~\textbf{cat~myfile} \par Hello \par\$\end{list}\end{figure} You can change the standard input of a command with the input redirection operator, <. For example, cat < myfile will display the contents of myfile. This is not useful in practice; for convenience, the cat command accepts a filename argument. So you can simply say cat myfile, and the effect will be the same. redirection operators Under the hood, cat < myfile means that the shell opens myfile and then feeds its contents to the standard input of cat. cat myfile, without the redirection operator, means that the cat command receives one argument (myfile) opens the file itself, and then displays the file. |
|