Add a small section on shell redirection and piping.
Fix two sentences to not start with a lower case command. Reviewed by: bcr, wblock
This commit is contained in:
parent
e11c3356e5
commit
202f060596
Notes:
svn2git
2020-12-08 03:00:23 +00:00
svn path=/head/; revision=43736
1 changed files with 77 additions and 3 deletions
|
@ -917,8 +917,8 @@ Other information:</screen>
|
||||||
</example>
|
</example>
|
||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>&man.chfn.1; and &man.chsh.1; are links to
|
<para>The commands &man.chfn.1; and &man.chsh.1; are links
|
||||||
&man.chpass.1;, as are &man.ypchpass.1;, &man.ypchfn.1;,
|
to &man.chpass.1;, as are &man.ypchpass.1;, &man.ypchfn.1;,
|
||||||
and &man.ypchsh.1;. Since <acronym>NIS</acronym> support
|
and &man.ypchsh.1;. Since <acronym>NIS</acronym> support
|
||||||
is automatic, specifying the <literal>yp</literal> before
|
is automatic, specifying the <literal>yp</literal> before
|
||||||
the command is not necessary. How to configure NIS is
|
the command is not necessary. How to configure NIS is
|
||||||
|
@ -987,7 +987,7 @@ passwd: done</screen>
|
||||||
<primary><command>pw</command></primary>
|
<primary><command>pw</command></primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
|
|
||||||
<para>&man.pw.8; is a command line utility to create, remove,
|
<para>The &man.pw.8; utility can create, remove,
|
||||||
modify, and display users and groups. It functions as a
|
modify, and display users and groups. It functions as a
|
||||||
front end to the system user and group files. &man.pw.8;
|
front end to the system user and group files. &man.pw.8;
|
||||||
has a very powerful set of command line options that make it
|
has a very powerful set of command line options that make it
|
||||||
|
@ -3432,6 +3432,80 @@ Swap: 2048M Total, 2048M Free
|
||||||
<para>Then, rerun &man.chsh.1;.</para>
|
<para>Then, rerun &man.chsh.1;.</para>
|
||||||
</note>
|
</note>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
|
<sect2>
|
||||||
|
<info>
|
||||||
|
<title>Advanced Shell Techniques</title>
|
||||||
|
|
||||||
|
<authorgroup>
|
||||||
|
<author>
|
||||||
|
<personname>
|
||||||
|
<firstname>Tom</firstname>
|
||||||
|
<surname>Rhodes</surname>
|
||||||
|
</personname>
|
||||||
|
<contrib>Written by </contrib>
|
||||||
|
</author>
|
||||||
|
</authorgroup>
|
||||||
|
</info>
|
||||||
|
|
||||||
|
<para>The &unix; shell is not just a command interpreter, it
|
||||||
|
acts as a powerful tool which allows users to execute commands,
|
||||||
|
redirect their output, redirect their input and chain commands
|
||||||
|
together to improve the final command output. When this functionality
|
||||||
|
is mixed with built in commands, the user is provided with
|
||||||
|
an environment that can maximize efficiency.</para>
|
||||||
|
|
||||||
|
<para>Shell redirection is the action of sending the output
|
||||||
|
or the input of a command into another command or into a
|
||||||
|
file. To capture the output of the &man.ls.1; command, for
|
||||||
|
example, into a file, simply redirect the output:</para>
|
||||||
|
|
||||||
|
<screen>&prompt.user; <userinput>ls > directory_listing.txt</userinput></screen>
|
||||||
|
|
||||||
|
<para>The <filename>directory_listing.txt</filename> file will
|
||||||
|
now contain the directory contents. Some commands allow you
|
||||||
|
to read input in a similar one, such as &man.sort.1;. To sort
|
||||||
|
this listing, redirect the input:</para>
|
||||||
|
|
||||||
|
<screen>&prompt.user; <userinput>sort < directory_listing.txt</userinput></screen>
|
||||||
|
|
||||||
|
<para>The input will be sorted and placed on the screen. To
|
||||||
|
redirect that input into another file, one could redirect
|
||||||
|
the output of &man.sort.1; by mixing the direction:</para>
|
||||||
|
|
||||||
|
<screen>&prompt.user; <userinput>sort < directory_listing.txt > sorted.txt</userinput></screen>
|
||||||
|
|
||||||
|
<para>In all of the previous examples, the commands are performing
|
||||||
|
redirection using file descriptors. Every unix system has file
|
||||||
|
descriptors; however, here we will focus on three, so named as
|
||||||
|
Standard Input, Standard Output, and Standard Error. Each one
|
||||||
|
has a purpose, where input could be a keyboard or a mouse,
|
||||||
|
something that provides input. Output could be a screen or
|
||||||
|
paper in a printer for example. And error would be anything
|
||||||
|
that is used for diagnostic or error messages. All three
|
||||||
|
are considered <acronym>I/O</acronym> based file descriptors
|
||||||
|
and sometimes considered streams.</para>
|
||||||
|
|
||||||
|
<para>Through the use of these descriptors, short named
|
||||||
|
stdin, stdout, and stderr, the shell allows output and
|
||||||
|
input to be passed around through various commands and
|
||||||
|
redirected to or from a file. Another method of redirection
|
||||||
|
is the pipe operator.</para>
|
||||||
|
|
||||||
|
<para>The &unix; pipe operator, <quote>|</quote> allows the
|
||||||
|
output of one command to be directly passed, or directed
|
||||||
|
to another program. Basically a pipe will allow the
|
||||||
|
standard output of a command to be passed as standard
|
||||||
|
input to another command, for example:</para>
|
||||||
|
|
||||||
|
<screen>&prompt.user; <userinput>cat directory_listing.txt | sort | less</userinput></screen>
|
||||||
|
|
||||||
|
<para>In that example, the contents of
|
||||||
|
<filename>directory_listing.txt</filename> will be sorted and
|
||||||
|
the output passed to &man.less.1;. This allows the user
|
||||||
|
to scroll through the output at their own pace and prevent
|
||||||
|
it from scrolling off the screen.</para>
|
||||||
|
</sect2>
|
||||||
</sect1>
|
</sect1>
|
||||||
|
|
||||||
<sect1 xml:id="editors">
|
<sect1 xml:id="editors">
|
||||||
|
|
Loading…
Reference in a new issue