NAME sh - shell (command line interpreter) SYNOPSIS sh [-vnx] [name [arg1 ..[arg9]]]. DESCRIPTION Sh is a command line interpreter: it reads lines typed by the user and interprets them as requests to execute other programs. Commands. In simplest form, a command line consists of the command name followed by arguments to the command, all separated by spaces: command arg1 arg2 ... argn The shell splits up the command name and the arguments into separate strings. Then a file with name command is sought; command may be a path name to specify any file in the system. If command is found, it is brought into memory and executed. The arguments collected by the shell are accessible to the command. When the command is finished, the shell resumes its own execution and indicates its readiness to accept another command by typing a prompt character. If file command cannot be found in the current directory or through its pathname, the shell searches a specific system directory of commands intended to be available to sh users in general. An example of a simple command is: sort list which would look for the tool 'sort' in the current directory, then in the system directory, and then sort the contents of file 'list', printing the output at the user's terminal. Some characters on the command line have special meanings to the shell (these are discussed below). The character '@' may be included anywhere in the command line to cause the following character to lose any special meaning it may have to the shell (to be 'escaped'). Sequences of characters enclosed in double (") or single (') quotes are also taken literally. Standard I/O Shell programs in general have open three standard files: 'input', 'output', and 'error output'. All three are assigned to the user's terminal unless redirected by the special arguments '<', '>', '?', '>>', '??', (and sometimes '-'). An argument of the form 'name' causes file 'name' to be used as the standard output. An argument of the form '?name' causes the file 'name' to be used as the standard error output. Arguments of the form '>>name' or '??name' cause program output to be appended to 'name' for standard output or error output respectively. If 'name' does not exist, it will be created. Most tools have the capability to read their input from a series of files. In this case, the list of files overrides reading from standard input. However, many of the tools allow the user to read from both a list of files and from input by specifying the filename '-' for standard input. For example, roff file1 - file2 would read its input from 'file1', then from the standard input, then from 'file2'. Filters and Pipes. The output from one command may be directed to the input of another. A sequence of commands separated by vertical bars (|) or carets ('^') causes the shell to arrange that the standard output of each command be delivered to the standard input of the next command in sequence. Thus in the command line: sort list | uniq | crt 'sort' sorts the contents of file 'list'; its output is passed to 'uniq', which strips out duplicate lines. The output from 'uniq' is then input to 'crt', which prepares the lines for viewing on the user's crt terminal. The vertical bar is called a 'pipe'. Programs such as 'sort', 'uniq', and 'crt', which copy standard input to standard output (making some changes along the way) are called 'filters'. Command separators Commands need not be on different lines; instead they may be separated by semicolons: ar t file; ed The above command will first list the contents of the archived file 'file', then enter the editor. The shell also allows commands to be grouped together with parentheses, where the group can then be used as a filter. For example, (date; cat chocolate) | comm vanilla writes first the date and then the file 'chocolate' to standard output, which is then read as input by 'comm'. This tool compares the results with existing file 'vanilla' to see which lines the two files have in common. Multitasking On many systems the shell also allows processes to be executed in the background. If a command is followed by '&', the shell will not wait for the command to finish before prompting again; instead, it is ready immediately to accept a new command. For instance, ratfor ambrose >george & preprocesses the file 'ambrose', putting the output on 'george'. No matter how long the compilation takes, the shell returns immediately. The identification number of the process running that command is printed. This identification may be used to wait for the completion of the command or to terminate it. The '&' may be used several times in a line. Parentheses and pipes are also allowed (within the same background process). Script files. The shell itself is a command, and may be called recursively, either implicitly or explicitly. This is primarily useful for executing files containing lines of shell commands. For instance, suppose you had a file named 'nbrcount' which looked like this: echo 'Counting strings of digits' tr $4 ar u loveletters $4 Then, executing the command private Dan John Harold fair would merge the files 'Dan', 'John', and 'Harold', encrypt them, and store them away in an archive under the name 'fair'. Script files may be used as filters in pipelines just like regular commands. Script files sometimes require in-line data to be available to them. A specj) != NEWLINE; k = k + 1) { file(k) = lin(j) j = j + 1 } file(k) = EOS if (k > 1) e standard input. However, within a shell procedure commands could be embedded this way: ed file <