.\" $OpenBSD: u4,v 1.2 2003/08/09 09:00:14 jmc Exp $ .\" .\" Copyright (C) Caldera International Inc. 2001-2002. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code and documentation must retain the above .\" copyright notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed or owned by Caldera .\" International, Inc. .\" 4. Neither the name of Caldera International, Inc. nor the names of other .\" contributors may be used to endorse or promote products derived from .\" this software without specific prior written permission. .\" .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .\" @(#)u4 8.1 (Berkeley) 6/8/93 .\" .SH IV. PROGRAMMING .PP There will be no attempt made to teach any of the programming languages available but a few words of advice are in order. One of the reasons why the .UC UNIX system is a productive programming environment is that there is already a rich set of tools available, and facilities like pipes, I/O redirection, and the capabilities of the shell often make it possible to do a job by pasting together programs that already exist instead of writing from scratch. .SH The Shell .PP The pipe mechanism lets you fabricate quite complicated operations out of spare parts that already exist. For example, the first draft of the .UL spell program was (roughly) .P1 .ta .6i 1.2i cat ... \f2collect the files\f3 | tr ... \f2put each word on a new line\f3 | tr ... \f2delete punctuation, etc.\f3 | sort \f2into dictionary order\f3 | uniq \f2discard duplicates\f3 | comm \f2print words in text\f3 \f2 but not in dictionary\f3 .P2 More pieces have been added subsequently, but this goes a long way for such a small effort. .PP The editor can be made to do things that would normally require special programs on other systems. For example, to list the first and last lines of each of a set of files, such as a book, you could laboriously type .P1 ed e chap1.1 1p $p e chap1.2 1p $p .ft R etc. .P2 But you can do the job much more easily. One way is to type .P1 ls chap* >temp .P2 to get the list of filenames into a file. Then edit this file to make the necessary series of editing commands (using the global commands of .UL ed ), and write it into .UL script . Now the command .P1 ed