.\" .\" Modified by Jeffrey Allen Neitzel . .\" .\" From: Version 6 (V6) UNIX /usr/[doc/]man/man1/sh.1 .\" .\" 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. .\" .TH SH I 5/15/74 .SH NAME sh \- shell (command interpreter) .SH SYNOPSIS .B sh [ .B \-t ] [ .B \-c ] [ name [ arg1 ... [ arg9 ] ] ] .SH DESCRIPTION .I Sh is the standard command interpreter. It is the program which reads and arranges the execution of the command lines typed by most users. It may itself be called as a command to interpret files of commands. Before discussing the arguments to the Shell used as a command, the structure of command lines themselves will be given. .PP .B "Commands." Each command is a sequence of non-blank command arguments separated by blanks. The first argument specifies the name of a command to be executed. Except for certain types of special arguments discussed below, the arguments other than the command name are passed without interpretation to the invoked command. .PP If the first argument is the name of an executable file, it is invoked; otherwise the string `/bin/' is prepended to the argument. (In this way most standard commands, which reside in `/bin', are found.) If no such command is found, the string `/usr' is further prepended (to give `/usr/bin/command') and another attempt is made to execute the resulting file. (Certain lesser-used commands live in `/usr/bin'.) .PP If a non-directory file has executable mode, but not the form of an executable program (does not begin with the proper magic number) then it is assumed to be an ASCII file of commands and a new Shell is created to execute it. See ``Argument passing'' below. .PP If the file cannot be found, a diagnostic is printed. .PP .B "Command lines." One or more commands separated by `|' or `^' constitute a chain of .IR filters . The standard output of each command but the last is taken as the standard input of the next command. Each command is run as a separate process, connected by pipes (see .IR pipe (II)) to its neighbors. A command line contained in parentheses `( )' may appear in place of a simple command as a filter. .PP A .I "command line" consists of one or more pipelines separated, and perhaps terminated by `;' or `&'. The semicolon designates sequential execution. The ampersand causes the preceding pipeline to be executed without waiting for it to finish. The process id of such a pipeline is reported, so that it may be used if necessary for a subsequent .IR kill . .PP .B "Termination Reporting." If a command (not followed by `&') terminates abnormally, a message is printed. (All terminations other than exit and interrupt are considered abnormal.) Termination reports for commands followed by `&' are given upon receipt of the first command subsequent to the termination of the command, or when a .B wait is executed. The following is a list of the abnormal termination messages: .PP .nf Bus error Trace/BPT trap Illegal instruction IOT trap EMT trap Bad system call Quit Floating exception Memory violation Killed Broken Pipe .fi .PP If a core image is produced, `\ \-\-\ Core\ dumped' is appended to the appropriate message. .PP .B "Redirection of I/O." There are three character sequences that cause the immediately following string to be interpreted as a special argument to the Shell itself. Such an argument may appear anywhere among the arguments of a simple command, or before or after a parenthesized command list, and is associated with that command or command list. .PP An argument of the form `arg' causes file `arg' to be used as the standard output (file descriptor 1) for the associated command. `Arg' is created if it did not exist, and in any case is truncated at the outset. .PP An argument of the form `>>arg' causes file `arg' to be used as the standard output for the associated command. If `arg' did not exist, it is created; if it did exist, the command output is appended to the file. .PP For example, either of the command lines .PP ls >junk; cat tail >>junk .br ( ls; cat tail ) >junk .PP creates, on file `junk', a listing of the working directory, followed immediately by the contents of file `tail'. .PP Either of the constructs `>arg' or `>>arg' associated with any but the last command of a pipeline is ineffectual, as is `', and other characters meaningful to the Shell may be passed as part of arguments. A special case of this feature allows the continuation of commands onto more than one line: a new-line preceded by `\\' is translated into a blank. .PP Sequences of characters enclosed in double (") or single (') quotes are also taken literally. For example: .PP ls | pr \-h "My directory" .PP causes a directory listing to be produced by .IR ls , and passed on to .I pr to be printed with the heading `My directory'. Quotes permit the inclusion of blanks in the heading, which is a single argument to .IR pr . .PP .B "Argument passing." When the Shell is invoked as a command, it has additional string processing capabilities. Recall that the form in which the Shell is invoked is .PP sh [ name [ arg1 ... [ arg9 ] ] ] .PP The .I name is the name of a file which is read and interpreted. If not given, this subinstance of the Shell continues to read the standard input file. .PP In command lines in the file (not in command input), character sequences of the form `$n', where .I n is a digit, are replaced by the \fIn\fRth argument to the invocation of the Shell (argn). `$0' is replaced by .IR name . .PP The argument `\-t', used alone, causes .I sh to read the standard input for a single line, execute it as a command, and then exit. This facility replaces the older `mini-shell'. It is useful for interactive programs which allow users to execute system commands. .PP The argument `\-c' (used with one following argument) causes the next argument to be taken as a command line and executed. No new-line need be present, but new-line characters are treated appropriately. This facility is useful as an alternative to `\-t' where the caller has already read some of the characters of the command to be executed. .PP .B "End of file." An end-of-file in the Shell's input causes it to exit. A side effect of this fact means that the way to log out from UNIX is to type an EOT. .PP .B "Special commands." The following commands are treated specially by the Shell. .TP .B chdir is done without spawning a new process by executing .IR chdir (II). .TP .B login is done by executing /bin/login without creating a new process. .TP .B wait is done without spawning a new process by executing .IR wait (II). .TP .B shift is done by manipulating the arguments to the Shell. .TP .B : is simply ignored. .PP .B "Command file errors; interrupts." Any Shell-detected error, or an interrupt signal, during the execution of a command file causes the Shell to cease execution of that file. .PP Processes that are created with `&' ignore interrupts. Also if such a process has not redirected its input with a `<', its input is automatically redirected to the zero length file /dev/null. .SH FILES /etc/glob, which interprets `*', `?', and `['. .br /dev/null as a source of end-of-file. .SH "SEE ALSO" `The UNIX Time-Sharing System', CACM, July, 1974, which gives the theory of operation of the Shell. .br chdir(I), login(I), shift(I), wait(I) .SH BUGS There is no way to redirect the diagnostic output.