From 5b57d28ffb6e1ef86b50f7d05d977826eae89bfe Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Fri, 1 Feb 2019 22:55:37 +0000 Subject: initial population --- bin/sh/USD.doc/Makefile | 12 + bin/sh/USD.doc/Rv7man | 405 ++++++++++++++++++++ bin/sh/USD.doc/referargs | 8 + bin/sh/USD.doc/t.mac | 69 ++++ bin/sh/USD.doc/t1 | 553 +++++++++++++++++++++++++++ bin/sh/USD.doc/t2 | 971 ++++++++++++++++++++++++++++++++++++++++++++++ bin/sh/USD.doc/t3 | 976 +++++++++++++++++++++++++++++++++++++++++++++++ bin/sh/USD.doc/t4 | 180 +++++++++ 8 files changed, 3174 insertions(+) create mode 100644 bin/sh/USD.doc/Makefile create mode 100644 bin/sh/USD.doc/Rv7man create mode 100644 bin/sh/USD.doc/referargs create mode 100644 bin/sh/USD.doc/t.mac create mode 100644 bin/sh/USD.doc/t1 create mode 100644 bin/sh/USD.doc/t2 create mode 100644 bin/sh/USD.doc/t3 create mode 100644 bin/sh/USD.doc/t4 (limited to 'bin/sh/USD.doc') diff --git a/bin/sh/USD.doc/Makefile b/bin/sh/USD.doc/Makefile new file mode 100644 index 0000000..55b7203 --- /dev/null +++ b/bin/sh/USD.doc/Makefile @@ -0,0 +1,12 @@ +# $NetBSD: Makefile,v 1.4 2014/07/05 19:23:00 dholland Exp $ +# @(#)Makefile 8.1 (Berkeley) 8/14/93 + +SECTION=reference/ref1 +ARTICLE=sh +SRCS= referargs t.mac t1 t2 t3 t4 +MACROS=-ms +ROFF_REFER=yes +#REFER_ARGS=-e -p Rv7man +EXTRAHTMLFILES=sh1.png sh2.png sh3.png sh4.png sh5.png + +.include diff --git a/bin/sh/USD.doc/Rv7man b/bin/sh/USD.doc/Rv7man new file mode 100644 index 0000000..628c67f --- /dev/null +++ b/bin/sh/USD.doc/Rv7man @@ -0,0 +1,405 @@ +%A L. P. Deutsch +%A B. W. Lampson +%T An online editor +%J Comm. Assoc. Comp. Mach. +%V 10 +%N 12 +%D December 1967 +%P 793-799, 803 +%K qed + +.[ +%r 17 +%K cstr +%R Comp. Sci. Tech. Rep. No. 17 +%I Bell Laboratories +%C Murray Hill, New Jersey +%A B. W. Kernighan +%A L. L. Cherry +%T A System for Typesetting Mathematics +%d May 1974, revised April 1977 +%J Comm. Assoc. Comp. Mach. +%K acm cacm +%V 18 +%P 151-157 +%D March 1975 +.] + +%T U\s-2NIX\s0 Time-Sharing System: Document Preparation +%K unix bstj +%A B. W. Kernighan +%A M. E. Lesk +%A J. F. Ossanna +%J Bell Sys. Tech. J. +%V 57 +%N 6 +%P 2115-2135 +%D 1978 + +%A T. A. Dolotta +%A J. R. Mashey +%T An Introduction to the Programmer's Workbench +%J Proc. 2nd Int. Conf. on Software Engineering +%D October 13-15, 1976 +%P 164-168 + +%T U\s-2NIX\s0 Time-Sharing System: The Programmer's Workbench +%A T. A. Dolotta +%A R. C. Haight +%A J. R. Mashey +%J Bell Sys. Tech. J. +%V 57 +%N 6 +%P 2177-2200 +%D 1978 +%K unix bstj + +%T U\s-2NIX\s0 Time-Sharing System: U\s-2NIX\s0 on a Microprocessor +%K unix bstj +%A H. Lycklama +%J Bell Sys. Tech. J. +%V 57 +%N 6 +%P 2087-2101 +%D 1978 + +%T The C Programming Language +%A B. W. Kernighan +%A D. M. Ritchie +%I Prentice-Hall +%C Englewood Cliffs, New Jersey +%D 1978 + +%T Computer Recreations +%A Aleph-null +%J Software Practice and Experience +%V 1 +%N 2 +%D April-June 1971 +%P 201-204 + +%T U\s-2NIX\s0 Time-Sharing System: The U\s-2NIX\s0 Shell +%A S. R. Bourne +%K unix bstj +%J Bell Sys. Tech. J. +%V 57 +%N 6 +%P 1971-1990 +%D 1978 + +%A L. P. Deutsch +%A B. W. Lampson +%T \*sSDS\*n 930 time-sharing system preliminary reference manual +%R Doc. 30.10.10, Project \*sGENIE\*n +%C Univ. Cal. at Berkeley +%D April 1965 + +%A R. J. Feiertag +%A E. I. Organick +%T The Multics input-output system +%J Proc. Third Symposium on Operating Systems Principles +%D October 18-20, 1971 +%P 35-41 + +%A D. G. Bobrow +%A J. D. Burchfiel +%A D. L. Murphy +%A R. S. Tomlinson +%T \*sTENEX\*n, a Paged Time Sharing System for the \*sPDP\*n-10 +%J Comm. Assoc. Comp. Mach. +%V 15 +%N 3 +%D March 1972 +%K tenex +%P 135-143 + +%A R. E. Griswold +%A D. R. Hanson +%T An Overview of SL5 +%J SIGPLAN Notices +%V 12 +%N 4 +%D April 1977 +%P 40-50 + +%A E. W. Dijkstra +%T Cooperating Sequential Processes +%B Programming Languages +%E F. Genuys +%I Academic Press +%C New York +%D 1968 +%P 43-112 + +%A J. A. Hawley +%A W. B. Meyer +%T M\s-2UNIX\s0, A Multiprocessing Version of U\s-2NIX\s0 +%K munix unix +%R M.S. Thesis +%I Naval Postgraduate School +%C Monterey, Cal. +%D 1975 + +%T The U\s-2NIX\s0 Time-Sharing System +%K unix bstj +%A D. M. Ritchie +%A K. Thompson +%J Bell Sys. Tech. J. +%V 57 +%N 6 +%P 1905-1929 +%D 1978 + +%A E. I. Organick +%T The M\s-2ULTICS\s0 System +%K multics +%I M.I.T. Press +%C Cambridge, Mass. +%D 1972 + +%T UNIX for Beginners +%A B. W. Kernighan +%D 1978 + +%T U\s-2NIX\s0 Programmer's Man\&ual +%A K. Thompson +%A D. M. Ritchie +%K unix +%I Bell Laboratories +%O Seventh Edition. +%D 1978 + +%A K. Thompson +%T The U\s-2NIX\s0 Command Language +%B Structured Programming\(emInfotech State of the Art Report +%I Infotech International Ltd. +%C Nicholson House, Maidenhead, Berkshire, England +%D March 1975 +%P 375-384 +%K unix +%X pwb +Brief description of shell syntax and semantics, without much +detail on implementation. +Much on pipes and convenience of hooking programs together. +Includes SERMONETTE: +"Many familiar computing `concepts' are missing from UNIX. +Files have no records. There are no access methods. +There are no file types. These concepts fill a much-needed gap. +I sincerely hope that when future systems are designed by +manufacturers the value of some of these ingrained notions is re-examined. +Like the politician and his `common man', manufacturers have +their `average user'. + +%A J. R. Mashey +%T PWB/UNIX Shell Tutorial +%D September 30, 1977 + +%A D. F. Hartley (Ed.) +%T The Cambridge Multiple Access System \- Users Reference Manual +%I University Mathematical Laboratory +%C Cambridge, England +%D 1968 + +%A P. A. Crisman (Ed.) +%T The Compatible Time-Sharing System +%I M.I.T. Press +%K whole ctss book +%C Cambridge, Mass. +%D 1965 + +%T LR Parsing +%A A. V. Aho +%A S. C. Johnson +%J Comp. Surveys +%V 6 +%N 2 +%P 99-124 +%D June 1974 + +%T Deterministic Parsing of Ambiguous Grammars +%A A. V. Aho +%A S. C. Johnson +%A J. D. Ullman +%J Comm. Assoc. Comp. Mach. +%K acm cacm +%V 18 +%N 8 +%P 441-452 +%D August 1975 + +%A A. V. Aho +%A J. D. Ullman +%T Principles of Compiler Design +%I Addison-Wesley +%C Reading, Mass. +%D 1977 + +.[ +%r 65 +%R Comp. Sci. Tech. Rep. No. 65 +%K CSTR +%A S. C. Johnson +%T Lint, a C Program Checker +%D December 1977 +%O updated version TM 78-1273-3 +%D 1978 +.] + +%T A Portable Compiler: Theory and Practice +%A S. C. Johnson +%J Proc. 5th ACM Symp. on Principles of Programming Languages +%P 97-104 +%D January 1978 + +.[ +%r 39 +%K CSTR +%R Comp. Sci. Tech. Rep. No. 39 +%I Bell Laboratories +%C Murray Hill, New Jersey +%A M. E. Lesk +%T Lex \(em A Lexical Analyzer Generator +%D October 1975 +.] + +.[ +%r 32 +%K CSTR +%R Comp. Sci. Tech. Rep. No. 32 +%I Bell Laboratories +%C Murray Hill, New Jersey +%A S. C. Johnson +%T Yacc \(em Yet Another Compiler-Compiler +%D July 1975 +.] + +%T U\s-2NIX\s0 Time-Sharing System: Portability of C Programs and the U\s-2NIX\s0 System +%K unix bstj +%A S. C. Johnson +%A D. M. Ritchie +%J Bell Sys. Tech. J. +%V 57 +%N 6 +%P 2021-2048 +%D 1978 + +%T Typing Documents on UNIX and GCOS: The -ms Macros for Troff +%A M. E. Lesk +%D 1977 + +%A K. Thompson +%A D. M. Ritchie +%T U\s-2NIX\s0 Programmer's Manual +%K unix +%I Bell Laboratories +%O Sixth Edition +%D May 1975 + +%T The Network U\s-2NIX\s0 System +%K unix +%A G. L. Chesson +%J Operating Systems Review +%V 9 +%N 5 +%P 60-66 +%D 1975 +%O Also in \f2Proc. 5th Symp. on Operating Systems Principles.\f1 + +%T Spider \(em An Experimental Data Communications System +%Z ctr127 +%A A. G. Fraser +%J Proc. IEEE Conf. on Communications +%P 21F +%O IEEE Cat. No. 74CH0859-9-CSCB. +%D June 1974 + +%T A Virtual Channel Network +%A A. G. Fraser +%J Datamation +%P 51-56 +%D February 1975 + +.[ +%r 41 +%K CSTR +%R Comp. Sci. Tech. Rep. No. 41 +%I Bell Laboratories +%C Murray Hill, New Jersey +%A J. W. Hunt +%A M. D. McIlroy +%T An Algorithm for Differential File Comparison +%D June 1976 +.] + +%A F. P. Brooks, Jr. +%T The Mythical Man-Month +%I Addison-Wesley +%C Reading, Mass. +%D 1975 +%X pwb +Readable, classic reference on software engineering and +problems of large projects, from someone with experience in them. +Required reading for any software engineer, even if conclusions may not +always be agreed with. +%br +"The second is the most dangerous system a man ever designs." p.55. +%br +"Hence plan to throw one away; you will, anyhow." p.116. +%br +"Cosgrove has perceptively pointed out that the programmer delivers +satisfaction of a user need rather than any tangible product. +And both the actual need and the user's perception of that need +will change as programs are built, tested, and used." p.117. +%br +"The total cost of maintaining a widely used program is typically 40 percent +or more of the cost of developing it." p.121. +%br +"As shown above, amalgamating prose and program reduces the total +number of characters to be stored." p.175. + +%T A Portable Compiler for the Language C +%A A. Snyder +%I Master's Thesis, M.I.T. +%C Cambridge, Mass. +%D 1974 + +%T The C Language Calling Sequence +%A M. E. Lesk +%A S. C. Johnson +%A D. M. Ritchie +%D 1977 + +%T Optimal Code Generation for Expression Trees +%A A. V. Aho +%A S. C. Johnson +%D 1975 +%J J. Assoc. Comp. Mach. +%K acm jacm +%V 23 +%N 3 +%P 488-501 +%O Also in \f2Proc. ACM Symp. on Theory of Computing,\f1 pp. 207-217, 1975. + +%A R. Sethi +%A J. D. Ullman +%T The Generation of Optimal Code for Arithmetic Expressions +%J J. Assoc. Comp. Mach. +%K acm jacm +%V 17 +%N 4 +%D October 1970 +%P 715-728 +%O Reprinted as pp. 229-247 in \fICompiler Techniques\fR, ed. B. W. Pollack, Auerbach, Princeton NJ (1972). +%X pwb +Optimal approach for straight-line, fixed +number of regs. + +%T Code Generation for Machines with Multiregister +Operations +%A A. V. Aho +%A S. C. Johnson +%A J. D. Ullman +%J Proc. 4th ACM Symp. on Principles of Programming Languages +%P 21-28 +%D January 1977 + diff --git a/bin/sh/USD.doc/referargs b/bin/sh/USD.doc/referargs new file mode 100644 index 0000000..3bb6284 --- /dev/null +++ b/bin/sh/USD.doc/referargs @@ -0,0 +1,8 @@ +.\" $NetBSD: referargs,v 1.1 2014/07/05 19:22:02 dholland Exp $ +.\" +.\" Arguments for refer; these were previously passed on the refer(1) +.\" command line: -e -p Rv7man +.R1 +accumulate +database Rv7man +.R2 diff --git a/bin/sh/USD.doc/t.mac b/bin/sh/USD.doc/t.mac new file mode 100644 index 0000000..9bf65c8 --- /dev/null +++ b/bin/sh/USD.doc/t.mac @@ -0,0 +1,69 @@ +.\" $NetBSD: t.mac,v 1.2 2010/08/22 02:19:07 perry 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: +.\" +.\" Redistributions of source code and documentation must retain the above +.\" copyright notice, this list of conditions and the following +.\" disclaimer. +.\" +.\" 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. +.\" +.\" 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. 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) RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" @(#)t.mac 8.1 (Berkeley) 8/14/93 +.\" +.ds ZZ \fB.\|.\|.\fP +.ds ST \v'.3m'\s+2*\s0\v'-.3m' +.ds DO \h'\w'do 'u' +.ds Ca \h'\w'case 'u' +.ds WH \h'\w'while 'u' +.ds VT \|\fB\(or\fP\| +.ds TH \h'\w'then 'u' +.ds DC \*(DO\*(Ca +.ds AP >\h'-.2m'> +.ds HE <\h'-.2m'< +. \" macros for algol 68c reference manual +.ds DA 1977 November 1 +.ds md \v'.25m' +.ds mu \v'-.25m' +.ds U \*(mu\s-3 +.ds V \s0\*(md +.ds L \*(md\s-3 +.ds M \s0\*(mu +.ds S \s-1 +.ds T \s0 +. \" small 1 +.ds O \*S1\*T +.ds h \| +.ds s \|\| +. \" ellipsis +.ds e .\|.\|. +. \" subscripts +.ds 1 \*(md\s-41\s0\*(mu +.ds 2 \*(md\s-42\s0\*(mu diff --git a/bin/sh/USD.doc/t1 b/bin/sh/USD.doc/t1 new file mode 100644 index 0000000..075511f --- /dev/null +++ b/bin/sh/USD.doc/t1 @@ -0,0 +1,553 @@ +.\" $NetBSD: t1,v 1.3 2010/08/22 02:19:07 perry 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: +.\" +.\" Redistributions of source code and documentation must retain the above +.\" copyright notice, this list of conditions and the following +.\" disclaimer. +.\" +.\" 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. +.\" +.\" All advertising materials mentioning features or use of this software +.\" must display the following acknowledgment: +.\" +.\" This product includes software developed or owned by Caldera +.\" International, Inc. 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) RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" @(#)t1 8.1 (Berkeley) 8/14/93 +.\" +.EH 'USD:3-%''An Introduction to the UNIX Shell' +.OH 'An Introduction to the UNIX Shell''USD:3-%' +.\".RP +.TL +An Introduction to the UNIX Shell +.AU +S. R. Bourne +.AI +Murray Hill, NJ +.AU +(Updated for 4.3BSD by Mark Seiden) +.AU +(Further updated by Perry E. Metzger)\(dg +.AB +.FS +\(dg This paper was updated in 2010 to reflect most features of modern +POSIX shells, which all follow the design of S.R. Bourne's original v7 +Unix shell. +Among these are ash, bash, ksh and others. +Typically one of these will be installed as /bin/sh on a modern system. +It does not describe the behavior of the c shell (csh). +If it's the c shell (csh) you're interested in, a good place to +begin is William Joy's paper "An Introduction to the C shell" (USD:4). +.FE +.LP +The +.ul +shell +is a command programming language that provides an interface +to the +.UX +operating system. +Its features include +control-flow primitives, parameter passing, variables and +string substitution. +Constructs such as +.ul +while, if then else, case +and +.ul +for +are available. +Two-way communication is possible between the +.ul +shell +and commands. +String-valued parameters, typically file names or flags, may be +passed to a command. +A return code is set by commands that may be used to determine control-flow, +and the standard output from a command may be used +as shell input. +.LP +The +.ul +shell +can modify the environment +in which commands run. +Input and output can be redirected +to files, and processes that communicate through `pipes' +can be invoked. +Commands are found by +searching directories +in the file system in a +sequence that can be defined by the user. +Commands can be read either from the terminal or from a file, +which allows command procedures to be +stored for later use. +.AE +.ds ST \v'.3m'\s+2*\s0\v'-.3m' +.SH +1.0\ Introduction +.LP +The shell is both a command language +and a programming language +that provides an interface to the UNIX +operating system. +This memorandum describes, with +examples, the UNIX shell. +The first section covers most of the +everyday requirements +of terminal users. +Some familiarity with UNIX +is an advantage when reading this section; +see, for example, +"UNIX for beginners". +.[ +unix beginn kernigh 1978 +.] +Section 2 describes those features +of the shell primarily intended +for use within shell procedures. +These include the control-flow +primitives and string-valued variables +provided by the shell. +A knowledge of a programming language +would be a help when reading this section. +The last section describes the more +advanced features of the shell. +References of the form "see \fIpipe\fP (2)" +are to a section of the UNIX manual. +.[ +seventh 1978 ritchie thompson +.] +.SH +1.1\ Simple\ commands +.LP +Simple commands consist of one or more words +separated by blanks. +The first word is the name of the command +to be executed; any remaining words +are passed as arguments to the command. +For example, +.DS + who +.DE +is a command that prints the names +of users logged in. +The command +.DS + ls \(mil +.DE +prints a list of files in the current +directory. +The argument \fI\(mil\fP tells \fIls\fP +to print status information, size and +the creation date for each file. +.SH +1.2\ Input\ output\ redirection +.LP +Most commands produce output on the standard output +that is initially connected to the terminal. +This output may be sent to a file +by writing, for example, +.DS + ls \(mil >file +.DE +The notation \fI>file\fP +is interpreted by the shell and is not passed +as an argument to \fIls.\fP +If \fIfile\fP does not exist then the +shell creates it; +otherwise the original contents of +\fIfile\fP are replaced with the output +from \fIls.\fP +Output may be appended to a file +using the notation +.DS + ls \(mil \*(APfile +.DE +In this case \fIfile\fP is also created if it does not already +exist. +.LP +The standard input of a command may be taken +from a file instead of the terminal by +writing, for example, +.DS + wc \|. +.\" For example +.\" .DS +.\" command some args >out 2>errors +.\" .DE +.\" will redirect standard output to the file `out' but standard error +.\" (and thus all error messages) to `errors'. +.\" The notation 2>&1 sets standard error pointing to the same +.\" place as standard out. +.\" Thus: +.\" .DS +.\" command some args 2>&1 >everything +.\" .DE +.\" will put both standard out and standard error into the file `everything'. +.\" See section 3.7 below for more details. +.SH +1.3\ Pipelines\ and\ filters +.LP +The standard output of one command may be +connected to the standard input of another +by writing +the `pipe' operator, +indicated by \*(VT, +as in, +.DS + ls \(mil \*(VT wc +.DE +Two commands connected in this way constitute +a \fIpipeline\fP and +the overall effect is the same as +.DS + ls \(mil >file; wc \*(ST ? \*(VT &\|,\fR +are called metacharacters. +A complete list of metacharacters is given +in appendix B. +Any character preceded by a \fB\\\fR is \fIquoted\fP +and loses its special meaning, if any. +The \fB\\\fP is elided so that +.DS + echo \\? +.DE +will echo a single \fB?\|,\fP +and +.DS + echo \\\\ +.DE +will echo a single \fB\\\|.\fR +To allow long strings to be continued over +more than one line +the sequence \fB\\newline\fP +is ignored. +.LP +\fB\\\fP is convenient for quoting +single characters. +When more than one character needs +quoting the above mechanism is clumsy and +error prone. +A string of characters may be quoted +by enclosing the string between single quotes. +For example, +.DS + echo xx\'\*(ST\*(ST\*(ST\*(ST\'xx +.DE +will echo +.DS + xx\*(ST\*(ST\*(ST\*(STxx +.DE +The quoted string may not contain +a single quote +but may contain newlines, which are preserved. +This quoting mechanism is the most +simple and is recommended +for casual use. +.LP +A third quoting mechanism using double quotes +is also available +that prevents interpretation of some but not all +metacharacters. +Discussion of the +details is deferred +to section 3.5\|. +.SH +1.7\ Prompting +.LP +When the shell is used from a terminal it will +issue a prompt before reading a command. +By default this prompt is `\fB$\ \fR'\|. +It may be changed by saying, +for example, +.DS + \s-1PS1\s0="yesdear$ " +.DE +that sets the prompt to be the string \fIyesdear$\|.\fP +If a newline is typed and further input is needed +then the shell will issue the prompt `\fB>\ \fR'\|. +Sometimes this can be caused by mistyping +a quote mark. +If it is unexpected then entering the interrupt character +(typically \s-1CONTROL-C\s0) +will return the shell to read another command. +This prompt may be changed by saying, for example, +.DS + \s-1PS2\s0=more +.DE +Entering the interrupt character may also be used to terminate most +programs running as the current foreground job. +.LP +(\s-1PS1\s0 and \s-1PS2\s0 are \fIshell variables\fP, which will be +described in section 2.4 below.) +.SH +1.8\ The\ shell\ and\ login +.LP +Following \fIlogin\fP(1) +the shell is called to read and execute +commands typed at the terminal. +If the user's login directory +contains the file \fB.profile\fP +then it is assumed to contain commands +and is read by the shell before reading +any commands from the terminal. +.LP +(Most versions of the shell also specify a file that is read and +executed on start-up whether or not the shell is invoked by login. +The \s-1ENV\s0 shell variable, described in section 2.4 below, can be +used to override the name of this file. +See the shell manual page for further information.) +.SH +1.9\ Summary +.sp +.RS +.IP \(bu +\fBls\fP +.br +Print the names of files in the current directory. +.IP \(bu +\fBls >file\fP +.br +Put the output from \fIls\fP into \fIfile.\fP +.IP \(bu +\fBls \*(VT wc \(mil\fR +.br +Print the number of files in the current directory. +.IP \(bu +\fBls \*(VT grep old\fR +.br +Print those file names containing the string \fIold.\fP +.IP \(bu +\fBls \*(VT grep old \*(VT wc \(mil\fR +.br +Print the number of files whose name contains the string \fIold.\fP +.IP \(bu +\fBcc pgm.c &\fR +.br +Run \fIcc\fP in the background. +.RE diff --git a/bin/sh/USD.doc/t2 b/bin/sh/USD.doc/t2 new file mode 100644 index 0000000..d49747e --- /dev/null +++ b/bin/sh/USD.doc/t2 @@ -0,0 +1,971 @@ +.\" $NetBSD: t2,v 1.3 2010/08/22 02:19:07 perry 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: +.\" +.\" Redistributions of source code and documentation must retain the above +.\" copyright notice, this list of conditions and the following +.\" disclaimer. +.\" +.\" 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. +.\" +.\" All advertising materials mentioning features or use of this software +.\" must display the following acknowledgment: +.\" +.\" This product includes software developed or owned by Caldera +.\" International, Inc. 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) RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" @(#)t2 8.1 (Berkeley) 6/8/93 +.\" +.SH +2.0\ Shell\ scripts +.LP +The shell may be used to read and execute commands +contained in a file. +For example, +.DS + sh file [ args \*(ZZ ] +.DE +calls the shell to read commands from \fIfile.\fP +Such a file is called a \fIshell script.\fP +Arguments may be supplied with the call +and are referred to in \fIfile\fP +using the positional parameters +\fB$1, $2, \*(ZZ\|.\fR +.LP +For example, if the file \fIwg\fP contains +.DS + who \*(VT grep $1 +.DE +then +.DS + sh wg fred +.DE +is equivalent to +.DS + who \*(VT grep fred +.DE +.LP +UNIX files have three independent attributes, +\fIread,\fP \fIwrite\fP and \fIexecute.\fP +The UNIX command \fIchmod\fP(1) may be used +to make a file executable. +For example, +.DS + chmod +x wg +.DE +will ensure that the file \fIwg\fP has execute status. +Following this, the command +.DS + wg fred +.DE +is equivalent to +.DS + sh wg fred +.DE +This allows shell scripts and other programs +to be used interchangeably. +In either case a new process is created to +run the command. +.LP +The `\fB#\fP' character is used as a comment character by the shell. +All characters following the `#' on a line are ignored. +.LP +A typical modern system has several different shells, some with differing +command syntax, and it is desirable to specify which one should be +invoked when an executable script is invoked. +If the special comment +.DS + #!/\fIpath\fP/\fIto\fP/\fIinterpreter\fP +.DE +appears as the first line in a script, it is used to specify the +absolute pathname of the shell (or other interpreter) that should be +used to execute the file. +(Without such a line, \fB/bin/sh\fP is assumed.) +It is best if a script explicitly states +what shell it is intended for in this manner. +.LP +As well as providing names for the positional +parameters, +the number of positional parameters to a script +is available as \fB$#\|.\fP +The name of the file being executed +is available as \fB$0\|.\fP +.LP +A special shell parameter \fB$\*(ST\fP +is used to substitute for all positional parameters +except \fB$0\|.\fP +A typical use of this is to provide +some default arguments, +as in, +.DS + nroff \(miT450 \(mims $\*(ST +.DE +which simply prepends some arguments +to those already given. +(The variable \fB$@\fP also expands to ``all positional +parameters'', but is subtly different when expanded inside quotes. +See section 3.5, below.) +.SH +2.1\ Control\ flow\ -\ for +.LP +A frequent use of shell scripts is to loop +through the arguments (\fB$1, $2, \*(ZZ\fR) +executing commands once for each argument. +An example of such a script is +\fItel\fP that searches the file +\fB/usr/share/telnos\fR +that contains lines of the form +.DS + \*(ZZ + fred mh0123 + bert mh0789 + \*(ZZ +.DE +The text of \fItel\fP is +.DS + #!/bin/sh + + for i + do + grep $i /usr/share/telnos + done +.DE +The command +.DS + tel fred +.DE +prints those lines in \fB/usr/share/telnos\fR +that contain the string \fIfred\|.\fP +.DS + tel fred bert +.DE +prints those lines containing \fIfred\fP +followed by those for \fIbert.\fP +.LP +The \fBfor\fP loop notation is recognized by the shell +and has the general form +.DS + \fBfor\fR \fIname\fR \fBin\fR \fIw1 w2 \*(ZZ\fR + \fBdo\fR \fIcommand-list\fR + \fBdone\fR +.DE +A \fIcommand-list\fP is a sequence of one or more +simple commands separated or terminated by a newline or semicolon. +Furthermore, reserved words +like \fBdo\fP and \fBdone\fP are only +recognized following a newline or +semicolon. +\fIname\fP is a shell variable that is set +to the words \fIw1 w2 \*(ZZ\fR in turn each time the \fIcommand-list\fP +following \fBdo\fP +is executed. +If \fBin\fR \fIw1 w2 \*(ZZ\fR +is omitted then the loop +is executed once for each positional parameter; +that is, \fBin\fR \fI$\*(ST\fR is assumed. +.LP +Another example of the use of the \fBfor\fP +loop is the \fIcreate\fP command +whose text is +.DS + for i do >$i; done +.DE +The command +.DS + create alpha beta +.DE +ensures that two empty files +\fIalpha\fP and \fIbeta\fP exist +and are empty. +The notation \fI>file\fP may be used on its +own to create or clear the contents of a file. +Notice also that a semicolon (or newline) is required before \fBdone.\fP +.SH +2.2\ Control\ flow\ -\ case +.LP +A multiple way branch is provided for by the +\fBcase\fP notation. +For example, +.DS + case $# in + \*(Ca1) cat \*(AP$1 ;; + \*(Ca2) cat \*(AP$2 <$1 ;; + \*(Ca\*(ST) echo \'usage: append [ from ] to\' ;; + esac +.DE +is an \fIappend\fP command. +When called +with one argument as +.DS + append file +.DE +\fB$#\fP is the string \fI1\fP and +the standard input is copied onto the +end of \fIfile\fP +using the \fIcat\fP command. +.DS + append file1 file2 +.DE +appends the contents of \fIfile1\fP +onto \fIfile2.\fP +If the number of arguments supplied to +\fIappend\fP is other than 1 or 2 +then a message is printed indicating +proper usage. +.LP +The general form of the \fBcase\fP command +is +.DS + \fBcase \fIword \fBin + \*(Ca\fIpattern\|\fB)\ \fIcommand-list\fB\|;; + \*(Ca\*(ZZ + \fBesac\fR +.DE +The shell attempts to match +\fIword\fR with each \fIpattern,\fR +in the order in which the patterns +appear. +If a match is found the +associated \fIcommand-list\fP is +executed and execution +of the \fBcase\fP is complete. +Since \*(ST is the pattern that matches any +string it can be used for the default case. +.LP +A word of caution: +no check is made to ensure that only +one pattern matches +the case argument. +The first match found defines the set of commands +to be executed. +In the example below the commands following +the second \*(ST will never be executed. +.DS + case $# in + \*(Ca\*(ST) \*(ZZ ;; + \*(Ca\*(ST) \*(ZZ ;; + esac +.DE +.LP +Another example of the use of the \fBcase\fP +construction is to distinguish +between different forms +of an argument. +The following example is a fragment of a \fIcc\fP command. +.DS + for i + do case $i in + \*(DC\(mi[ocs]) \*(ZZ ;; + \*(DC\(mi\*(ST) echo "unknown flag $i" ;; + \*(DC\*(ST.c) /lib/c0 $i \*(ZZ ;; + \*(DC\*(ST) echo "unexpected argument $i" ;; + \*(DOesac + done +.DE +.LP +To allow the same commands to be associated +with more than one pattern +the \fBcase\fP command provides +for alternative patterns +separated by a \*(VT\|. +For example, +.DS + case $i in + \*(Ca\(mix\*(VT\(miy) \*(ZZ + esac +.DE +is equivalent to +.DS + case $i in + \*(Ca\(mi[xy]) \*(ZZ + esac +.DE +.LP +The usual quoting conventions apply +so that +.DS + case $i in + \*(Ca\\?) \*(ZZ +.DE +will match the character \fB?\|.\fP +.SH +2.3\ Here\ documents +.LP +The shell script \fItel\fP +in section 2.1 uses the file \fB/usr/share/telnos\fR +to supply the data +for \fIgrep.\fP +An alternative is to include this +data +within the shell script as a \fIhere\fP document, as in, +.DS + for i + do grep $i \*(HE! + \*(DO\*(ZZ + \*(DOfred mh0123 + \*(DObert mh0789 + \*(DO\*(ZZ + ! + done +.DE +In this example +the shell takes the lines between \fB\*(HE!\fR and \fB!\fR +as the standard input for \fIgrep.\fP +The string \fB!\fR is arbitrary, the document +being terminated by a line that consists +of the string following \*(HE\|. +.LP +Parameters are substituted in the document +before it is made available to \fIgrep\fP +as illustrated by the following script +called \fIedg\|.\fP +.DS + ed $3 \*(HE% + g/$1/s//$2/g + w + % +.DE +The call +.DS + edg string1 string2 file +.DE +is then equivalent to the command +.DS + ed file \*(HE% + g/string1/s//string2/g + w + % +.DE +and changes all occurrences of \fIstring1\fP +in \fIfile\fP to \fIstring2\|.\fP +Substitution can be prevented using \\ +to quote the special character \fB$\fP +as in +.DS + ed $3 \*(HE+ + 1,\\$s/$1/$2/g + w + + +.DE +(This version of \fIedg\fP is equivalent to +the first except that \fIed\fP will print +a \fB?\fR if there are no occurrences of +the string \fB$1\|.\fP) +Substitution within a \fIhere\fP document +may be prevented entirely by quoting +the terminating string, +for example, +.DS + grep $i \*(HE'end' + \*(ZZ + end +.DE +The document is presented +without modification to \fIgrep.\fP +If parameter substitution is not required +in a \fIhere\fP document this latter form +is more efficient. +.SH +2.4\ Shell\ variables\(dg +.LP +.FS +Also known as \fIenvironment variables\fB, see \fIenvironment\fB(7). +.FE +The shell +provides string-valued variables. +Variable names begin with a letter +and consist of letters, digits and +underscores. +Variables may be given values by writing, for example, +.DS + user=fred\ box=m000\ acct=mh0000 +.DE +which assigns values to the variables +\fBuser, box\fP and \fBacct.\fP +A variable may be set to the null string +by saying, for example, +.DS + null= +.DE +The value of a variable is substituted +by preceding its name with \fB$\|\fP; +for example, +.DS + echo $user +.DE +will echo \fIfred.\fP +.LP +Variables may be used interactively +to provide abbreviations for frequently +used strings. +For example, +.DS + b=/usr/fred/bin + mv pgm $b +.DE +will move the file \fIpgm\fP +from the current directory to the directory \fB/usr/fred/bin\|.\fR +A more general notation is available for parameter +(or variable) +substitution, as in, +.DS + echo ${user} +.DE +which is equivalent to +.DS + echo $user +.DE +and is used when the parameter name is +followed by a letter or digit. +For example, +.DS + tmp=/tmp/ps + ps a >${tmp}a +.DE +will direct the output of \fIps\fR +to the file \fB/tmp/psa,\fR +whereas, +.DS + ps a >$tmpa +.DE +would cause the value of the variable \fBtmpa\fP +to be substituted. +.LP +Except for \fB$?\fP the following +are set initially by the shell. +\fB$?\fP is set after executing each command. +.RS +.IP \fB$?\fP 8 +The exit status (return code) +of the last command executed +as a decimal string. +Most commands return a zero exit status +if they complete successfully, +otherwise a non-zero exit status is returned. +Testing the value of return codes is dealt with +later under \fBif\fP and \fBwhile\fP commands. +.IP \fB$#\fP 8 +The number of positional parameters +(in decimal). +Used, for example, in the \fIappend\fP command +to check the number of parameters. +.IP \fB$$\fP 8 +The process number of this shell (in decimal). +Since process numbers are unique among +all existing processes, this string is +frequently used to generate +unique +temporary file names. +For example, +.DS + ps a >/tmp/ps$$ + \*(ZZ + rm /tmp/ps$$ +.DE +.IP \fB$\|!\fP 8 +The process number of the last process +run in the background (in decimal). +.IP \fB$\(mi\fP 8 +The current shell flags, such as +\fB\(mix\fR and \fB\(miv\|.\fR +.RE +.LP +Some variables have a special meaning to the +shell and should be avoided for general +use. +.RS +.IP \fB$\s-1MAIL\s0\fP 8 +When used interactively +the shell looks at the file +specified by this variable +before it issues a prompt. +If the specified file has been modified +since it +was last looked at the shell +prints the message +\fIyou have mail\fP before prompting +for the next command. +This variable is typically set +in the file \fB.profile,\fP +in the user's login directory. +For example, +.DS + \s-1MAIL\s0=/usr/spool/mail/fred +.DE +.IP \fB$\s-1HOME\s0\fP 8 +The default argument +for the \fIcd\fP command. +The current directory is used to resolve +file name references that do not begin with +a \fB/\|,\fR +and is changed using the \fIcd\fP command. +For example, +.DS + cd /usr/fred/bin +.DE +makes the current directory \fB/usr/fred/bin\|.\fR +.DS + cat wn +.DE +will print on the terminal the file \fIwn\fP +in this directory. +The command +\fIcd\fP with no argument +is equivalent to +.DS + cd $\s-1HOME\s0 +.DE +This variable is also typically set in the +the user's login profile. +.IP \fB$\s-1PWD\s0\fP 8 +The current working directory. Set by the \fIcd\fB command. +.IP \fB$\s-1PATH\s0\fP 8 +A list of directories that contain commands (the \fIsearch path\fR\|). +Each time a command is executed by the shell +a list of directories is searched +for an executable file. +.ne 5 +If \fB$\s-1PATH\s0\fP is not set +then the current directory, +\fB/bin\fP, and \fB/usr/bin\fP are searched by default. +.ne 5 +Otherwise \fB$\s-1PATH\s0\fP consists of directory +names separated by \fB:\|.\fP +For example, +.DS + \s-1PATH\s0=\fB:\fP/usr/fred/bin\fB:\fP/bin\fB:\fP/usr/bin +.DE +specifies that the current directory +(the null string before the first \fB:\fP\|), +\fB/usr/fred/bin, /bin \fRand\fP /usr/bin\fR +are to be searched in that order. +In this way individual users +can have their own `private' commands +that are accessible independently +of the current directory. +If the command name contains a \fB/\fR then this directory search +is not used; a single attempt +is made to execute the command. +.IP \fB$\s-1PS1\s0\fP 8 +The primary shell prompt string, by default, `\fB$\ \fR'. +.IP \fB$\s-1PS2\s0\fP 8 +The shell prompt when further input is needed, +by default, `\fB>\ \fR'. +.IP \fB$\s-1IFS\s0\fP 8 +The set of characters used by \fIblank +interpretation\fR (see section 3.5). +.IP \fB$\s-1ENV\s0\fP 8 +The shell reads and executes the commands in the file +specified by this variable when it is initially started. +Unlike the \fB.profile\fP file, these commands are executed by all +shells, not just the one started at login. +(Most versions of the shell specify a filename that is used if +\s-1ENV\s0 is not explicitly set. See the manual page for your shell.) +.RE +.SH +2.5\ The\ test\ command +.LP +The \fItest\fP command, although not part of the shell, +is intended for use by shell programs. +For example, +.DS + test \(mif file +.DE +returns zero exit status if \fIfile\fP +exists and non-zero exit status otherwise. +In general \fItest\fP evaluates a predicate +and returns the result as its exit status. +Some of the more frequently used \fItest\fP +arguments are given here, see \fItest\fP(1) +for a complete specification. +.DS + test s true if the argument \fIs\fP is not the null string + test \(mif file true if \fIfile\fP exists + test \(mir file true if \fIfile\fP is readable + test \(miw file true if \fIfile\fP is writable + test \(mid file true if \fIfile\fP is a directory +.DE +The \fItest\fP command is known as `\fB[\fP' and may be invoked as +such. +For aesthetic reasons, the command ignores a close bracket `\fB]\fP' given +at the end of a command so +.DS + [ -f filename ] +.DE +and +.DS + test -f filename +.DE +are completely equivalent. +Typically, the bracket notation is used when \fItest\fP is invoked inside +shell control constructs. +.SH +2.6\ Control\ flow\ -\ while +.LP +The actions of +the \fBfor\fP loop and the \fBcase\fP +branch are determined by data available to the shell. +A \fBwhile\fP or \fBuntil\fP loop +and an \fBif then else\fP branch +are also provided whose +actions are determined by the exit status +returned by commands. +A \fBwhile\fP loop has the general form +.DS + \fBwhile\fP \fIcommand-list\*1\fP + \fBdo\fP \fIcommand-list\*2\fP + \fBdone\fP +.DE +.LP +The value tested by the \fBwhile\fP command +is the exit status of the last simple command +following \fBwhile.\fP +Each time round the loop +\fIcommand-list\*1\fP is executed; +if a zero exit status is returned then +\fIcommand-list\*2\fP +is executed; +otherwise, the loop terminates. +For example, +.DS + while [ $1 ] + do \*(ZZ + \*(DOshift + done +.DE +is equivalent to +.DS + for i + do \*(ZZ + done +.DE +\fIshift\fP is a shell command that +renames the positional parameters +\fB$2, $3, \*(ZZ\fR as \fB$1, $2, \*(ZZ\fR +and loses \fB$1\|.\fP +.LP +Another kind of use for the \fBwhile/until\fP +loop is to wait until some +external event occurs and then run +some commands. +In an \fBuntil\fP loop +the termination condition is reversed. +For example, +.DS + until [ \(mif file ] + do sleep 300; done + \fIcommands\fP +.DE +will loop until \fIfile\fP exists. +Each time round the loop it waits for +5 minutes before trying again. +(Presumably another process +will eventually create the file.) +.LP +The most recent enclosing loop may be exited with the \fBbreak\fP +command, or the rest of the body skipped and the next iteration begun +with the \fBcontinue\fP command. +.LP +The commands \fItrue\fP(1) and \fIfalse\fP(1) return 0 and non-zero +exit statuses respectively. They are sometimes of use in control flow, +e.g.: +.DS + while true + do date; sleep 5 + done +.DE +is an infinite loop that prints the date and time every five seconds. +.SH +2.7\ Control\ flow\ -\ if +.LP +Also available is a +general conditional branch +of the form, +.DS + \fBif\fP \fIcommand-list + \fBthen \fIcommand-list + \fBelse \fIcommand-list + \fBfi\fR +.DE +that tests the value returned by the last simple command +following \fBif.\fP +.LP +The \fBif\fP command may be used +in conjunction with the \fItest\fP command +to test for the existence of a file as in +.DS + if [ \(mif file ] + then \fIprocess file\fP + else \fIdo something else\fP + fi +.DE +.LP +An example of the use of \fBif, case\fP +and \fBfor\fP constructions is given in +section 2.10\|. +.LP +A multiple test \fBif\fP command +of the form +.DS + if \*(ZZ + then \*(ZZ + else if \*(ZZ + then \*(ZZ + else if \*(ZZ + \*(ZZ + fi + fi + fi +.DE +may be written using an extension of the \fBif\fP +notation as, +.DS + if \*(ZZ + then \*(ZZ + elif \*(ZZ + then \*(ZZ + elif \*(ZZ + \*(ZZ + fi +.DE +.LP +The following example is an implementation of the \fItouch\fP command +which changes the `last modified' time for a list +of files. +The command may be used in conjunction +with \fImake\fP(1) to force recompilation of a list +of files. +.DS + #!/bin/sh + + flag= + for i + do case $i in + \*(DC\(mic) flag=N ;; + \*(DC\*(ST) if [ \(mif $i ] + \*(DC then cp $i junk$$; mv junk$$ $i + \*(DC elif [ $flag ] + \*(DC then echo file \\'$i\\' does not exist + \*(DC else >$i + \*(DC fi + \*(DO esac + done +.DE +The \fB\(mic\fP flag is used in this command to +force subsequent files to be created if they do not already exist. +Otherwise, if the file does not exist, an error message is printed. +The shell variable \fIflag\fP +is set to some non-null string if the \fB\(mic\fP +argument is encountered. +The commands +.DS + cp \*(ZZ; mv \*(ZZ +.DE +copy the file and then overwrite it with the copy, +thus causing the last modified date to be updated. +.LP +The sequence +.DS + if command1 + then command2 + fi +.DE +may be written +.DS + command1 && command2 +.DE +Conversely, +.DS + command1 \*(VT\*(VT command2 +.DE +executes \fIcommand2\fP only if \fIcommand1\fP +fails. +In each case the value returned +is that of the last simple command executed. +.LP +Placing a `\fB!\fP' in front of a pipeline inverts its exit +status, almost in the manner of the C operator of the same name. +Thus: +.DS + if ! [ -d $1 ] + then + echo $1 is not a directory + fi +.DE +will print a message only if $1 is not a directory. +.SH +2.8\ Command\ grouping +.LP +Commands may be grouped in two ways, +.DS + \fB{\fI command-list\fB ; }\fR +.DE +and +.DS + \fB(\fI command-list\fB )\fR +.DE +.LP +In the first \fIcommand-list\fP is simply executed. +The second form executes \fIcommand-list\fP +as a separate process. +For example, +.DS + (cd x; rm junk ) +.DE +executes \fIrm junk\fP in the directory +\fBx\fP without changing the current +directory of the invoking shell. +.LP +The commands +.DS + cd x; rm junk +.DE +have the same effect but leave the invoking +shell in the directory \fBx.\fP +.SH +2.9\ Shell\ Functions +.LP +A function may be defined by the syntax +.DS + \fIfuncname\fP() \fB{\fI command-list\fB ; }\fR +.DE +Functions are invoked within a script as though they were separate +commands of the same name. +While they are executed, the +positional parameters \fB$1, $2, \*(ZZ\fR are temporarily set to the +arguments passed to the function. For example: +.DS + count() { + echo $2 : $# + } + + count a b c +.DE +would print `b : 3'. +.SH +2.10\ Debugging\ shell\ scripts +.LP +The shell provides two tracing mechanisms +to help when debugging shell scripts. +The first is invoked within the script +as +.DS + set \(miv +.DE +(\fBv\fP for verbose) and causes lines of the +script to be printed as they are read. +It is useful to help isolate syntax errors. +It may be invoked without modifying the script +by saying +.DS + sh \(miv \fIscript\fP \*(ZZ +.DE +where \fIscript\fP is the name of the shell script. +This flag may be used in conjunction +with the \fB\(min\fP flag which prevents +execution of subsequent commands. +(Note that saying \fIset \(min\fP at a terminal +will render the terminal useless +until an end-of-file is typed.) +.LP +The command +.DS + set \(mix +.DE +will produce an execution +trace. +Following parameter substitution +each command is printed as it is executed. +(Try these at the terminal to see +what effect they have.) +Both flags may be turned off by saying +.DS + set \(mi +.DE +and the current setting of the shell flags is available as \fB$\(mi\|\fR. +.SH +2.11\ The\ man\ command +.LP +The following is a simple implementation of the \fIman\fP command, +which is used to display sections of the UNIX manual on your terminal. +It is called, for example, as +.DS + man sh + man \(mit ed + man 2 fork +.DE +In the first the manual section for \fIsh\fP +is displayed.. +Since no section is specified, section 1 is used. +The second example will typeset (\fB\(mit\fP option) +the manual section for \fIed.\fP +The last prints the \fIfork\fP manual page +from section 2, which covers system calls. +.sp 2 +.DS + #!/bin/sh + + cd /usr/share/man + + # "#" is the comment character + # default is nroff ($N), section 1 ($s) + N=n\ s=1 + + for i + do case $i in +.sp .5 + \*(DC[1\(mi9]\*(ST) s=$i ;; +.sp .5 + \*(DC\(mit) N=t ;; +.sp .5 + \*(DC\(min) N=n ;; +.sp .5 + \*(DC\(mi\*(ST) echo unknown flag \\'$i\\' ;; +.sp .5 + \*(DC\*(ST) if [ \(mif man$s/$i.$s ] + \*(DC then + \*(DC ${N}roff \(miman man$s/$i.$s + \*(DC else # look through all manual sections + \*(DC found=no + \*(DC for j in 1 2 3 4 5 6 7 8 9 + \*(DC do + \*(DC \*(DOif [ \(mif man$j/$i.$j ] + \*(DC \*(DOthen + \*(DC \*(DO\*(THman $j $i + \*(DC \*(DO\*(THfound=yes + \*(DC \*(DO\*(THbreak + \*(DC \*(DOfi + \*(DC done + \*(DC case $found in + \*(DC \*(Cano) echo \\'$i: manual page not found\\' + \*(DC esac + \*(DC fi + \*(DOesac + done +.DE +.ce +.ft B +Figure 1. A version of the man command +.ft R diff --git a/bin/sh/USD.doc/t3 b/bin/sh/USD.doc/t3 new file mode 100644 index 0000000..aab53ee --- /dev/null +++ b/bin/sh/USD.doc/t3 @@ -0,0 +1,976 @@ +.\" $NetBSD: t3,v 1.3 2010/08/22 02:19:07 perry 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: +.\" +.\" Redistributions of source code and documentation must retain the above +.\" copyright notice, this list of conditions and the following +.\" disclaimer. +.\" +.\" 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. +.\" +.\" 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. 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) RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" @(#)t3 8.1 (Berkeley) 6/8/93 +.\" +.SH +3.0\ Keyword\ parameters +.LP +Shell variables may be given values +by assignment +or when a shell script is invoked. +An argument to a command of the form +\fIname=value\fP +that precedes the command name +causes \fIvalue\fP +to be assigned to \fIname\fP +before execution of the command begins. +The value of \fIname\fP in the invoking +shell is not affected. +For example, +.DS + user=fred\ command +.DE +will execute \fIcommand\fP with +\fBuser\fP set to \fIfred\fP. +.\" Removed by Perry Metzger because -k is not in POSIX +.\" +.\" The \fB\(mik\fR flag causes arguments of the form +.\" \fIname=value\fP to be interpreted in this way +.\" anywhere in the argument list. +.\" Such \fInames\fP are sometimes +.\" called keyword parameters. +.\" If any arguments remain they +.\" are available as positional +.\" parameters \fB$1, $2, \*(ZZ\|.\fP +.LP +The \fIset\fP command +may also be used to set positional parameters +from within a script. +For example, +.DS + set\ \(mi\(mi\ \*(ST +.DE +will set \fB$1\fP to the first file name +in the current directory, \fB$2\fP to the next, +and so on. +Note that the first argument, \(mi\(mi, ensures correct treatment +when the first file name begins with a \(mi\|. +.LP +.SH +3.1\ Parameter\ transmission +.LP +When a command is executed both positional parameters +and shell variables may be set on invocation. +Variables are also made available implicitly +to a command +by specifying in advance that such parameters +are to be exported from the invoking shell. +For example, +.DS + export\ user\ box=red +.DE +marks the variables \fBuser\fP and \fBbox\fP +for export (setting \fBbox\fP to ``red'' in the process). +When a command is invoked +copies are made of all exportable variables +(also known as \fIenvironment variables\fP) +for use within the invoked program. +Modification of such variables +within an invoked command does not +affect the values in the invoking shell. +It is generally true of +a shell script or other program +that it +cannot modify the state +of its caller without explicit +actions on the part of the caller. +.\" Removed by Perry Metzger because this is confusing to beginners. +.\" +.\" (Shared file descriptors are an +.\" exception to this rule.) +.LP +Names whose value is intended to remain +constant may be declared \fIreadonly\|.\fP +The form of this command is the same as that of the \fIexport\fP +command, +.DS + readonly name[=value] \*(ZZ +.DE +Subsequent attempts to set readonly variables +are illegal. +.SH +3.2\ Parameter\ substitution +.LP +If a shell parameter is not set +then the null string is substituted for it. +For example, if the variable \fBd\fP +is not set +.DS + echo $d +.DE +or +.DS + echo ${d} +.DE +will echo nothing. +A default string may be given +as in +.DS + echo ${d:\(mi\fB.\fR} +.DE +which will echo +the value of the variable \fBd\fP +if it is set and not null and `\fB.\fP' otherwise. +The default string is evaluated using the usual +quoting conventions so that +.DS + echo ${d:\(mi\'\*(ST\'} +.DE +will echo \fB\*(ST\fP if the variable \fBd\fP +is not set or null. +Similarly +.DS + echo ${d:\(mi$1} +.DE +will echo the value of \fBd\fP if it is set and not null +and the value (if any) of \fB$1\fP otherwise. +.LP +The notation ${d:+\fB.\fR} performs the inverse operation. It +substitutes `\fB.\fP' if \fBd\fP is set or not null, and otherwise +substitutes null. +.LP +A variable may be assigned a default value +using +the notation +.DS + echo ${d:=\fB.\fR} +.DE +which substitutes the same string as +.DS + echo ${d:\(mi\fB.\fR} +.DE +and if \fBd\fP were not previously set or null +then it will be set to the string `\fB.\fP'\|. +.LP +If there is no sensible default then +the notation +.DS + echo ${d:?\fImessage\fP} +.DE +will echo the value of the variable \fBd\fP if it is set and not null, +otherwise \fImessage\fP is printed by the shell and +execution of the shell script is abandoned. +If \fImessage\fP is absent then a standard message +is printed. +A shell script that requires some variables +to be set might start as follows: +.DS + :\ ${user:?}\ ${acct:?}\ ${bin:?} + \*(ZZ +.DE +Colon (\fB:\fP) is a command +that is +built in to the shell and does nothing +once its arguments have been evaluated. +If any of the variables \fBuser, acct\fP +or \fBbin\fP are not set then the shell +will abandon execution of the script. +.SH +3.3\ Command\ substitution +.LP +The standard output from a command can be +substituted in a similar way to parameters. +The command \fIpwd\fP prints on its standard +output the name of the current directory. +For example, if the current directory is +\fB/usr/fred/bin\fR +then the commands +.DS + d=$(pwd) +.DE +(or the older notation d=\`pwd\`) +is equivalent to +.DS + d=/usr/fred/bin +.DE +.LP +The entire string inside $(\*(ZZ)\| (or between grave accents \`\*(ZZ\`) +is taken as the command +to be executed +and is replaced with the output from +the command. +(The difference between the $(\*(ZZ) and \`\*(ZZ\` notations is that +the former may be nested, while the latter cannot be.) +.LP +The command is written using the usual quoting conventions, +except that inside \`\*(ZZ\` +a \fB\`\fR must be escaped using +a \fB\\\|\fR. +For example, +.DS + ls $(echo "$HOME") +.DE +is equivalent to +.DS + ls $HOME +.DE +Command substitution occurs in all contexts +where parameter substitution occurs (including \fIhere\fP documents) and the +treatment of the resulting text is the same +in both cases. +This mechanism allows string +processing commands to be used within +shell scripts. +An example of such a command is \fIbasename\fP +which removes a specified suffix from a string. +For example, +.DS + basename main\fB.\fPc \fB.\fPc +.DE +will print the string \fImain\|.\fP +Its use is illustrated by the following +fragment from a \fIcc\fP command. +.DS + case $A in + \*(Ca\*(ZZ + \*(Ca\*(ST\fB.\fPc) B=$(basename $A \fB.\fPc) + \*(Ca\*(ZZ + esac +.DE +that sets \fBB\fP to the part of \fB$A\fP +with the suffix \fB.c\fP stripped. +.LP +Here are some composite examples. +.RS +.IP \(bu +.ft B +for i in \`ls \(mit\`; do \*(ZZ +.ft R +.br +The variable \fBi\fP is set +to the names of files in time order, +most recent first. +.IP \(bu +.ft B +set \(mi\(mi\| \`date\`; echo $6 $2 $3, $4 +.ft R +.br +will print, e.g., +.ft I +1977 Nov 1, 23:59:59 +.ft R +.RE +.SH +3.4\ Arithmetic\ Expansion +.LP +Within a $((\*(ZZ)) construct, integer arithmetic operations are +evaluated. +(The $ in front of variable names is optional within $((\*(ZZ)). +For example: +.DS + x=5; y=1 + echo $(($x+3*2)) + echo $((y+=x)) + echo $y +.DE +will print `11', then `6', then `6' again. +Most of the constructs permitted in C arithmetic operations are +permitted though some (like `++') are not universally supported \(em +see the shell manual page for details. +.SH +3.5\ Evaluation\ and\ quoting +.LP +The shell is a macro processor that +provides parameter substitution, command substitution and file +name generation for the arguments to commands. +This section discusses the order in which +these evaluations occur and the +effects of the various quoting mechanisms. +.LP +Commands are parsed initially according to the grammar +given in appendix A. +Before a command is executed +the following +substitutions occur. +.RS +.IP \(bu +parameter substitution, e.g. \fB$user\fP +.IP \(bu +command substitution, e.g. \fB$(pwd)\fP or \fB\`pwd\`\fP +.IP \(bu +arithmetic expansion, e.g. \fB$(($count+1))\fP +.RS +.LP +Only one evaluation occurs so that if, for example, the value of the variable +\fBX\fP +is the string \fI$y\fP +then +.DS + echo $X +.DE +will echo \fI$y\|.\fP +.RE +.IP \(bu +blank interpretation +.RS +.LP +Following the above substitutions +the resulting characters +are broken into non-blank words (\fIblank interpretation\fP). +For this purpose `blanks' are the characters of the string +\fB$\s-1IFS\s0\fP. +By default, this string consists of blank, tab and newline. +The null string +is not regarded as a word unless it is quoted. +For example, +.DS + echo \'\' +.DE +will pass on the null string as the first argument to \fIecho\fP, +whereas +.DS + echo $null +.DE +will call \fIecho\fR with no arguments +if the variable \fBnull\fP is not set +or set to the null string. +.RE +.IP \(bu +file name generation +.RS +.LP +Each word +is then scanned for the file pattern characters +\fB\*(ST, ?\fR and \fB[\*(ZZ]\fR +and an alphabetical list of file names +is generated to replace the word. +Each such file name is a separate argument. +.RE +.RE +.LP +The evaluations just described also occur +in the list of words associated with a \fBfor\fP +loop. +Only substitution occurs +in the \fIword\fP used +for a \fBcase\fP branch. +.LP +As well as the quoting mechanisms described +earlier using \fB\\\fR and \fB\'\*(ZZ\'\fR +a third quoting mechanism is provided using double quotes. +Within double quotes parameter and command substitution +occurs but file name generation and the interpretation +of blanks does not. +The following characters +have a special meaning within double quotes +and may be quoted using \fB\\\|.\fP +.DS + \fB$ \fPparameter substitution + \fB$()\fP command substitution + \fB\`\fP command substitution + \fB"\fP ends the quoted string + \fB\e\fP quotes the special characters \fB$ \` " \e\fP +.DE +For example, +.DS + echo "$x" +.DE +will pass the value of the variable \fBx\fP as a +single argument to \fIecho.\fP +Similarly, +.DS + echo "$\*(ST" +.DE +will pass the positional parameters as a single +argument and is equivalent to +.DS + echo "$1 $2 \*(ZZ" +.DE +The notation \fB$@\fP +is the same as \fB$\*(ST\fR +except when it is quoted. +.DS + echo "$@" +.DE +will pass the positional parameters, unevaluated, to \fIecho\fR +and is equivalent to +.DS + echo "$1" "$2" \*(ZZ +.DE +.LP +The following table gives, for each quoting mechanism, +the shell metacharacters that are evaluated. +.DS +.ce +.ft I +metacharacter +.ft +.in 1.5i + \e $ * \` " \' +\' n n n n n t +\` y n n t n n +" y y n y t n + + t terminator + y interpreted + n not interpreted + +.in +.ft B +.ce +Figure 2. Quoting mechanisms +.ft +.DE +.LP +In cases where more than one evaluation of a string +is required the built-in command \fIeval\fP +may be used. +For example, +if the variable \fBX\fP has the value +\fI$y\fP, and if \fBy\fP has the value \fIpqr\fP +then +.DS + eval echo $X +.DE +will echo the string \fIpqr\|.\fP +.LP +In general the \fIeval\fP command +evaluates its arguments (as do all commands) +and treats the result as input to the shell. +The input is read and the resulting command(s) +executed. +For example, +.DS + wg=\'eval who\*(VTgrep\' + $wg fred +.DE +is equivalent to +.DS + who\*(VTgrep fred +.DE +In this example, +\fIeval\fP is required +since there is no interpretation +of metacharacters, such as \fB\*(VT\|\fR, following +substitution. +.SH +3.6\ Error\ handling +.LP +The treatment of errors detected by +the shell depends on the type of error +and on whether the shell is being +used interactively. +An interactive shell is one whose +input and output are connected +to a terminal. +.\" Removed by Perry Metzger, obsolete and excess detail +.\" +.\" (as determined by +.\" \fIgtty\fP (2)). +A shell invoked with the \fB\(mii\fP +flag is also interactive. +.LP +Execution of a command (see also 3.7) may fail +for any of the following reasons. +.IP \(bu +Input output redirection may fail. +For example, if a file does not exist +or cannot be created. +.IP \(bu +The command itself does not exist +or cannot be executed. +.IP \(bu +The command terminates abnormally, +for example, with a "bus error" +or "memory fault". +See Figure 2 below for a complete list +of UNIX signals. +.IP \(bu +The command terminates normally +but returns a non-zero exit status. +.LP +In all of these cases the shell +will go on to execute the next command. +Except for the last case an error +message will be printed by the shell. +All remaining errors cause the shell +to exit from a script. +An interactive shell will return +to read another command from the terminal. +Such errors include the following. +.IP \(bu +Syntax errors. +e.g., if \*(ZZ then \*(ZZ done +.IP \(bu +A signal such as interrupt. +The shell waits for the current +command, if any, to finish execution and +then either exits or returns to the terminal. +.IP \(bu +Failure of any of the built-in commands +such as \fIcd.\fP +.LP +The shell flag \fB\(mie\fP +causes the shell to terminate +if any error is detected. +.DS +1 hangup +2 interrupt +3* quit +4* illegal instruction +5* trace trap +6* IOT instruction +7* EMT instruction +8* floating point exception +9 kill (cannot be caught or ignored) +10* bus error +11* segmentation violation +12* bad argument to system call +13 write on a pipe with no one to read it +14 alarm clock +15 software termination (from \fIkill\fP (1)) + +.DE +.ft B +.ce +Figure 3. UNIX signals\(dg +.ft +.FS +\(dg Additional signals have been added in modern Unix. +See \fIsigvec\fP(2) or \fIsignal\fP(3) for an up-to-date list. +.FE +Those signals marked with an asterisk +produce a core dump +if not caught. +However, +the shell itself ignores quit which is the only +external signal that can cause a dump. +The signals in this list of potential interest +to shell programs are 1, 2, 3, 14 and 15. +.SH +3.7\ Fault\ handling +.LP +shell scripts normally terminate +when an interrupt is received from the +terminal. +The \fItrap\fP command is used +if some cleaning up is required, such +as removing temporary files. +For example, +.DS + trap\ \'rm\ /tmp/ps$$; exit\'\ 2 +.DE +sets a trap for signal 2 (terminal +interrupt), and if this signal is received +will execute the commands +.DS + rm /tmp/ps$$; exit +.DE +\fIexit\fP is +another built-in command +that terminates execution of a shell script. +The \fIexit\fP is required; otherwise, +after the trap has been taken, +the shell will resume executing +the script +at the place where it was interrupted. +.LP +UNIX signals can be handled in one of three ways. +They can be ignored, in which case +the signal is never sent to the process. +They can be caught, in which case the process +must decide what action to take when the +signal is received. +Lastly, they can be left to cause +termination of the process without +it having to take any further action. +If a signal is being ignored +on entry to the shell script, for example, +by invoking it in the background (see 3.7) then \fItrap\fP +commands (and the signal) are ignored. +.LP +The use of \fItrap\fP is illustrated +by this modified version of the \fItouch\fP +command (Figure 4). +The cleanup action is to remove the file \fBjunk$$\fR\|. +.DS + #!/bin/sh + + flag= + trap\ \'rm\ \(mif\ junk$$;\ exit\'\ 1 2 3 15 + for i + do\ case\ $i\ in + \*(DC\(mic) flag=N ;; + \*(DC\*(ST) if\ test\ \(mif\ $i + \*(DC then cp\ $i\ junk$$;\ mv\ junk$$ $i + \*(DC elif\ test\ $flag + \*(DC then echo\ file\ \\'$i\\'\ does\ not\ exist + \*(DC else >$i + \*(DC fi + \*(DOesac + done +.DE +.sp +.ft B +.ce +Figure 4. The touch command +.ft +.sp +The \fItrap\fP command +appears before the creation +of the temporary file; +otherwise it would be +possible for the process +to die without removing +the file. +.LP +Since there is no signal 0 in UNIX +it is used by the shell to indicate the +commands to be executed on exit from the +shell script. +.LP +A script may, itself, elect to +ignore signals by specifying the null +string as the argument to trap. +The following fragment is taken from the +\fInohup\fP command. +.DS + trap \'\' 1 2 3 15 +.DE +which causes \fIhangup, interrupt, quit \fRand\fI kill\fR +to be ignored both by the +script and by invoked commands. +.LP +Traps may be reset by saying +.DS + trap 2 3 +.DE +which resets the traps for signals 2 and 3 to their default values. +A list of the current values of traps may be obtained +by writing +.DS + trap +.DE +.LP +The script \fIscan\fP (Figure 5) is an example +of the use of \fItrap\fP where there is no exit +in the trap command. +\fIscan\fP takes each directory +in the current directory, prompts +with its name, and then executes +commands typed at the terminal +until an end of file or an interrupt is received. +Interrupts are ignored while executing +the requested commands but cause +termination when \fIscan\fP is +waiting for input. +.DS + d=\`pwd\` + for\ i\ in\ \*(ST + do\ if\ test\ \(mid\ $d/$i + \*(DOthen\ cd\ $d/$i + \*(DO\*(THwhile\ echo\ "$i:" + \*(DO\*(TH\*(WHtrap\ exit\ 2 + \*(DO\*(TH\*(WHread\ x + \*(DO\*(THdo\ trap\ :\ 2;\ eval\ $x;\ done + \*(DOfi + done +.DE +.sp +.ft B +.ce +Figure 5. The scan command +.ft +.sp +\fIread x\fR is a built-in command that reads one line from the +standard input +and places the result in the variable \fBx\|.\fP +It returns a non-zero exit status if either +an end-of-file is read or an interrupt +is received. +.SH +3.8\ Command\ execution +.LP +To run a command (other than a built-in) the shell first creates +a new process using the system call \fIfork.\fP +The execution environment for the command +includes input, output and the states of signals, and +is established in the child process +before the command is executed. +The built-in command \fIexec\fP +is used in the rare cases when no fork +is required +and simply replaces the shell with a new command. +For example, a simple version of the \fInohup\fP +command looks like +.DS + trap \\'\\' 1 2 3 15 + exec $\*(ST +.DE +The \fItrap\fP turns off the signals specified +so that they are ignored by subsequently created commands +and \fIexec\fP replaces the shell by the command +specified. +.LP +Most forms of input output redirection have already been +described. +In the following \fIword\fP is only subject +to parameter and command substitution. +No file name generation or blank interpretation +takes place so that, for example, +.DS + echo \*(ZZ >\*(ST.c +.DE +will write its output into a file whose name is \fB\*(ST.c\|.\fP +Input output specifications are evaluated left to right +as they appear in the command. +.IP >\ \fIword\fP 12 +The standard output (file descriptor 1) +is sent to the file \fIword\fP which is +created if it does not already exist. +.IP \*(AP\ \fIword\fP 12 +The standard output is sent to file \fIword.\fP +If the file exists then output is appended +(by seeking to the end); +otherwise the file is created. +.IP <\ \fIword\fP 12 +The standard input (file descriptor 0) +is taken from the file \fIword.\fP +.IP \*(HE\ \fIword\fP 12 +The standard input is taken from the lines +of shell input that follow up to but not +including a line consisting only of \fIword.\fP +If \fIword\fP is quoted then no interpretation +of the document occurs. +If \fIword\fP is not quoted +then parameter and command substitution +occur and \fB\\\fP is used to quote +the characters \fB\\\fP \fB$\fP \fB\`\fP and the first character +of \fIword.\fP +In the latter case \fB\\newline\fP is ignored (c.f. quoted strings). +.IP >&\ \fIdigit\fP 12 +The file descriptor \fIdigit\fP is duplicated using the system +call \fIdup\fP (2) +and the result is used as the standard output. +.IP <&\ \fIdigit\fP 12 +The standard input is duplicated from file descriptor \fIdigit.\fP +.IP <&\(mi 12 +The standard input is closed. +.IP >&\(mi 12 +The standard output is closed. +.LP +Any of the above may be preceded by a digit in which +case the file descriptor created is that specified by the digit +instead of the default 0 or 1. +For example, +.DS + \*(ZZ 2>file +.DE +runs a command with message output (file descriptor 2) +directed to \fIfile.\fP +.DS + \*(ZZ 2>&1 +.DE +runs a command with its standard output and message output +merged. +(Strictly speaking file descriptor 2 is created +by duplicating file descriptor 1 but the effect is usually to +merge the two streams.) +.\" Removed by Perry Metzger, most of this is now obsolete +.\" +.\" .LP +.\" The environment for a command run in the background such as +.\" .DS +.\" list \*(ST.c \*(VT lpr & +.\" .DE +.\" is modified in two ways. +.\" Firstly, the default standard input +.\" for such a command is the empty file \fB/dev/null\|.\fR +.\" This prevents two processes (the shell and the command), +.\" which are running in parallel, from trying to +.\" read the same input. +.\" Chaos would ensue +.\" if this were not the case. +.\" For example, +.\" .DS +.\" ed file & +.\" .DE +.\" would allow both the editor and the shell +.\" to read from the same input at the same time. +.\" .LP +.\" The other modification to the environment of a background +.\" command is to turn off the QUIT and INTERRUPT signals +.\" so that they are ignored by the command. +.\" This allows these signals to be used +.\" at the terminal without causing background +.\" commands to terminate. +.\" For this reason the UNIX convention +.\" for a signal is that if it is set to 1 +.\" (ignored) then it is never changed +.\" even for a short time. +.\" Note that the shell command \fItrap\fP +.\" has no effect for an ignored signal. +.SH +3.9\ Invoking\ the\ shell +.LP +The following flags are interpreted by the shell +when it is invoked. +If the first character of argument zero is a minus, +then commands are read from the file \fB.profile\|.\fP +.IP \fB\(mic\fP\ \fIstring\fP +.br +If the \fB\(mic\fP flag is present then +commands are read from \fIstring\|.\fP +.IP \fB\(mis\fP +If the \fB\(mis\fP flag is present or if no +arguments remain +then commands are read from the standard input. +Shell output is written to +file descriptor 2. +.IP \fB\(mii\fP +If the \fB\(mii\fP flag is present or +if the shell input and output are attached to a terminal (as told by \fIgtty\fP) +then this shell is \fIinteractive.\fP +In this case TERMINATE is ignored (so that \fBkill 0\fP +does not kill an interactive shell) and INTERRUPT is caught and ignored +(so that \fBwait\fP is interruptable). +In all cases QUIT is ignored by the shell. +.SH +3.10\ Job\ Control +.LP +When a command or pipeline (also known as a \fIjob\fP) is running in +the foreground, entering the stop character (typically +\s-1CONTROL-Z\s0 but user settable with the \fIstty\fP(1) command) +will usually cause the job to stop. +.LP +The jobs associated with the current shell may be listed by entering +the \fIjobs\fP command. +Each job has an associated \fIjob number\fP. +Jobs that are stopped may be continued by entering +.DS + bg %\fIjobnumber\fP +.DE +and jobs may be moved to the foreground by entering +.DS + fg %\fIjobnumber\fP +.DE +If there is a sole job with a particular name (say only one instance +of \fIcc\fP running), \fIfg\fP and \fIbg\fP may also use name of the +command in place of the number, as in: +.DS + bg %cc +.DE +If no `\fB%\fP' clause is entered, most recently stopped job +(indicated with a `+' by the \fIjobs\fP command) will be assumed. +See the manual page for the shell for more details. +.SH +3.11\ Aliases +.LP +The \fIalias\fP command creates a so-called shell alias, which is an +abbreviation that macro-expands at run time into some other command. +For example: +.DS + alias ls="ls -F" +.DE +would cause the command sequence \fBls -F\fP to be executed whenever +the user types \fBls\fP into the shell. +Note that if the user types \fBls -a\fP, the shell will in fact +execute \fBls -F -a\fP. +The command \fBalias\fP on its own prints out all current aliases. +The \fIunalias\fP command, as in: +.DS + unalias ls +.DE +will remove an existing alias. +Aliases can shadow pre-existing commands, as in the example above. +They are typically used to override the interactive behavior of +commands in small ways, for example to always invoke some program with +a favorite option, and are almost never found in scripts. +.SH +3.12\ Command\ Line\ Editing\ and\ Recall +.LP +When working interactively with the shell, it is often tedious to +retype previously entered commands, especially if they are complicated. +The shell therefore maintains a so-called \fIhistory\fP, which is +stored in the file specified by the \fB\s-1HISTFILE\s0\fP environment +variable if it is set. +Users may view, edit, and re-enter previous lines of input using +a small subset of the commands of the \fIvi\fP(1) or +\fIemacs\fP(1)\(dg editors. +.FS +Technically, vi command editing is standardized by POSIX while emacs +is not. +However, all modern shells support both styles. +.FE +Emacs style editing may be selected by entering +.DS + set -o emacs +.DE +and vi style editing may be selected with +.DS + set -o vi +.DE +The details of how command line editing works are beyond the scope of +this document. +See the shell manual page for details. +.SH +Acknowledgements +.LP +The design of the shell is +based in part on the original UNIX shell +.[ +unix command language thompson +.] +and the PWB/UNIX shell, +.[ +pwb shell mashey unix +.] +some +features having been taken from both. +Similarities also exist with the +command interpreters +of the Cambridge Multiple Access System +.[ +cambridge multiple access system hartley +.] +and of CTSS. +.[ +ctss +.] +.LP +I would like to thank Dennis Ritchie +and John Mashey for many +discussions during the design of the shell. +I am also grateful to the members of the Computing Science Research Center +and to Joe Maranzano for their +comments on drafts of this document. +.SH +.[ +$LIST$ +.] diff --git a/bin/sh/USD.doc/t4 b/bin/sh/USD.doc/t4 new file mode 100644 index 0000000..7719d6c --- /dev/null +++ b/bin/sh/USD.doc/t4 @@ -0,0 +1,180 @@ +.\" $NetBSD: t4,v 1.3 2010/08/22 02:19:07 perry 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: +.\" +.\" Redistributions of source code and documentation must retain the above +.\" copyright notice, this list of conditions and the following +.\" disclaimer. +.\" +.\" 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. +.\" +.\" 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. 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) RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" @(#)t4 8.1 (Berkeley) 8/14/93 +.\" +.bp +.SH +Appendix\ A\ -\ Grammar +.LP +Note: This grammar needs updating, it is obsolete. +.LP +.LD +\fIitem: word + input-output + name = value +.sp 0.7 +simple-command: item + simple-command item +.sp 0.7 +command: simple-command + \fB( \fIcommand-list \fB) + \fB{ \fIcommand-list \fB} + \fBfor \fIname \fBdo \fIcommand-list \fBdone + \fBfor \fIname \fBin \fIword \*(ZZ \fBdo \fIcommand-list \fBdone + \fBwhile \fIcommand-list \fBdo \fIcommand-list \fBdone + \fBuntil \fIcommand-list \fBdo \fIcommand-list \fBdone + \fBcase \fIword \fBin \fIcase-part \*(ZZ \fBesac + \fBif \fIcommand-list \fBthen \fIcommand-list \fIelse-part \fBfi +.sp 0.7 +\fIpipeline: command + pipeline \fB\*(VT\fI command +.sp 0.7 +andor: pipeline + andor \fB&&\fI pipeline + andor \fB\*(VT\*(VT\fI pipeline +.sp 0.7 +command-list: andor + command-list \fB;\fI + command-list \fB&\fI + command-list \fB;\fI andor + command-list \fB&\fI andor +.sp 0.7 +input-output: \fB> \fIfile + \fB< \fIfile + \fB\*(AP \fIword + \fB\*(HE \fIword +.sp 0.7 +file: word + \fB&\fI digit + \fB&\fI \(mi +.sp 0.7 +case-part: pattern\fB ) \fIcommand-list\fB ;; +.sp 0.7 +\fIpattern: word + pattern \fB\*(VT\fI word +.sp 0.7 +\fIelse-part: \fBelif \fIcommand-list\fB then\fI command-list else-part\fP + \fBelse \fIcommand-list\fI + empty +.sp 0.7 +empty: +.sp 0.7 +word: \fRa sequence of non-blank characters\fI +.sp 0.7 +name: \fRa sequence of letters, digits or underscores starting with a letter\fI +.sp 0.7 +digit: \fB0 1 2 3 4 5 6 7 8 9\fP +.DE +.LP +.bp +.SH +Appendix\ B\ -\ Meta-characters\ and\ Reserved\ Words +.LP +a) syntactic +.RS +.IP \fB\*(VT\fR 6 +pipe symbol +.IP \fB&&\fR 6 +`andf' symbol +.IP \fB\*(VT\*(VT\fR 6 +`orf' symbol +.IP \fB;\fP 8 +command separator +.IP \fB;;\fP 8 +case delimiter +.IP \fB&\fP 8 +background commands +.IP \fB(\ )\fP 8 +command grouping +.IP \fB<\fP 8 +input redirection +.IP \fB\*(HE\fP 8 +input from a here document +.IP \fB>\fP 8 +output creation +.IP \fB\*(AP\fP 8 +output append +.sp 2 +.RE +.LP +b) patterns +.RS +.IP \fB\*(ST\fP 8 +match any character(s) including none +.IP \fB?\fP 8 +match any single character +.IP \fB[...]\fP 8 +match any of the enclosed characters +.sp 2 +.RE +.LP +c) substitution +.RS +.IP \fB${...}\fP 8 +substitute shell variable +.IP \fB$(...)\fP 8 +substitute command output +.IP \fB\`...\`\fP 8 +substitute command output +.IP \fB$((...))\fP 8 +substitute arithmetic expression +.sp 2 +.RE +.LP +d) quoting +.RS +.IP \fB\e\fP 8 +quote the next character +.IP \fB\'...\'\fP 8 +quote the enclosed characters except for \' +.IP \fB"\&..."\fP 8 +quote the enclosed characters except +for \fB$ \` \e "\fP +.sp 2 +.RE +.LP +e) reserved words +.DS +.ft B +if then else elif fi +case in esac +for while until do done +! { } +.ft +.DE -- cgit v1.2.3-70-g09d2