svn commit: r43736 - head/en_US.ISO8859-1/books/handbook/basics

Tom Rhodes trhodes at
Mon Feb 3 18:54:03 UTC 2014

Author: trhodes
Date: Mon Feb  3 18:54:03 2014
New Revision: 43736

  Add a small section on shell redirection and piping.
  Fix two sentences to not start with a lower case command.
  Reviewed by:	bcr, wblock


Modified: head/en_US.ISO8859-1/books/handbook/basics/chapter.xml
--- head/en_US.ISO8859-1/books/handbook/basics/chapter.xml	Mon Feb  3 17:35:21 2014	(r43735)
+++ head/en_US.ISO8859-1/books/handbook/basics/chapter.xml	Mon Feb  3 18:54:03 2014	(r43736)
@@ -917,8 +917,8 @@ Other information:</screen>
-	  <para>&man.chfn.1; and &man.chsh.1; are links to
-	    &man.chpass.1;, as are &man.ypchpass.1;, &man.ypchfn.1;,
+	  <para>The commands &man.chfn.1; and &man.chsh.1; are links
+	    to &man.chpass.1;, as are &man.ypchpass.1;, &man.ypchfn.1;,
 	    and &man.ypchsh.1;.  Since <acronym>NIS</acronym> support
 	    is automatic, specifying the <literal>yp</literal> before
 	    the command is not necessary.  How to configure NIS is
@@ -987,7 +987,7 @@ passwd: done</screen>
-	<para>&; is a command line utility to create, remove,
+	<para>The &; utility can create, remove,
 	  modify, and display users and groups.  It functions as a
 	  front end to the system user and group files.  &;
 	  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>
+    <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 &; 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 xml:id="editors">

More information about the svn-doc-all mailing list