83 lines
4.1 KiB
HTML
83 lines
4.1 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
|
<!Converted with LaTeX2HTML 95.1 (Fri Jan 20 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
|
<HEAD>
|
|
<TITLE>3.8.1 Standard input and output</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value="3.8.1 Standard input and output">
|
|
<meta name="keywords" value="gs">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<BR> <HR><A NAME=tex2html3278 HREF="node121.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A> <A NAME=tex2html3276 HREF="node119.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A> <A NAME=tex2html3270 HREF="node119.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <A NAME=tex2html3280 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif"></A> <A NAME=tex2html3281 HREF="node250.html"><IMG ALIGN=BOTTOM ALT="index" SRC="index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html3279 HREF="node121.html">3.8.2 Redirecting input and </A>
|
|
<B>Up:</B> <A NAME=tex2html3277 HREF="node119.html">3.8 UNIX Plumbing</A>
|
|
<B> Previous:</B> <A NAME=tex2html3271 HREF="node119.html">3.8 UNIX Plumbing</A>
|
|
<BR> <HR> <P>
|
|
<H2><A NAME=SECTION00581000000000000000>3.8.1 Standard input and output</A></H2>
|
|
<P>
|
|
<A NAME=3031> </A>
|
|
<A NAME=3032> </A>
|
|
<A NAME=3033> </A>
|
|
<A NAME=3034> </A>
|
|
Many UNIX commands get input from what is known as <b>standard input</b>
|
|
and send their output to <b>standard output</b> (often abbreviated as ``stdin''
|
|
and ``stdout''). Your shell sets things up so that standard input is
|
|
your keyboard, and standard output is the screen.
|
|
<P>
|
|
Here's an example using the command <tt>cat</tt>. Normally, <tt>cat</tt> reads data
|
|
from all of the filenames given on the command line and sends this data
|
|
directly to stdout. Therefore, using the command
|
|
<P><TT> /home/larry/papers# <em>cat history-final masters-thesis</em>
|
|
<P></TT>
|
|
will display the contents of the file <tt>history-final</tt> followed by
|
|
<tt>masters-thesis</tt>.
|
|
<P>
|
|
However, if no filenames are given to <tt>cat</tt> as parameters, it
|
|
instead reads data from stdin, and sends it back to stdout. Here's an
|
|
example.
|
|
<P><TT> /home/larry/papers# <em>cat</em> <BR>
|
|
<em>Hello there.</em> <BR>
|
|
Hello there. <BR>
|
|
<em>Bye.</em> <BR>
|
|
Bye. <BR>
|
|
<IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img181.gif"> <BR>
|
|
/home/larry/papers#
|
|
<P></TT>
|
|
<A NAME=3051> </A>
|
|
<A NAME=3052> </A>
|
|
As you can see, each line that the user types (displayed in italics)
|
|
is immediately echoed back by the <tt>cat</tt> command. When reading from
|
|
standard input, commands know that the input is ``finished'' when they
|
|
receive an EOT (end-of-text) signal. In general, this is generated by pressing
|
|
<IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img182.gif">.
|
|
<P>
|
|
|
|
<P>
|
|
Here's another example. The command <tt>sort</tt> reads in lines of
|
|
text (again, from stdin, unless files are given on the command line),
|
|
and sends the sorted output to stdout. Try the following.
|
|
<P><TT> /home/larry/papers# <em>sort</em> <BR>
|
|
<em>bananas</em> <BR>
|
|
<em>carrots</em> <BR>
|
|
<em>apples</em> <BR>
|
|
<IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img183.gif"> <BR>
|
|
apples <BR>
|
|
bananas <BR>
|
|
carrots <BR>
|
|
/home/larry/papers#
|
|
<P></TT>
|
|
Now we can alphabetize our shopping list... isn't UNIX useful?
|
|
<P>
|
|
<BR> <HR><A NAME=tex2html3278 HREF="node121.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A> <A NAME=tex2html3276 HREF="node119.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A> <A NAME=tex2html3270 HREF="node119.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <A NAME=tex2html3280 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif"></A> <A NAME=tex2html3281 HREF="node250.html"><IMG ALIGN=BOTTOM ALT="index" SRC="index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html3279 HREF="node121.html">3.8.2 Redirecting input and </A>
|
|
<B>Up:</B> <A NAME=tex2html3277 HREF="node119.html">3.8 UNIX Plumbing</A>
|
|
<B> Previous:</B> <A NAME=tex2html3271 HREF="node119.html">3.8 UNIX Plumbing</A>
|
|
<BR> <HR> <P>
|
|
<BR> <HR>
|
|
<P><ADDRESS>
|
|
<I>Matt Welsh <BR>
|
|
mdw@sunsite.unc.edu</I>
|
|
</ADDRESS>
|
|
</BODY>
|