.\" This module is believed to contain source code proprietary to AT&T. .\" Use and redistribution is subject to the Berkeley Software License .\" Agreement and your Software Agreement with AT&T (Western Electric). .\" .\" @(#)p4 8.1 (Berkeley) 6/8/93 .\" .\" $FreeBSD$ .SH VI. THE SHELL .PP For most users, communication with the system is carried on with the aid of a program called the \&shell. The \&shell is a command-line interpreter: it reads lines typed by the user and interprets them as requests to execute other programs. (The \&shell is described fully elsewhere, .[ bourne shell bstj %Q This issue .] so this section will discuss only the theory of its operation.) In simplest form, a command line consists of the command name followed by arguments to the command, all separated by spaces: .P1 command arg\*s\d1\u\*n arg\*s\d2\u\*n .\|.\|. arg\*s\dn\u\*n .P2 The \&shell splits up the command name and the arguments into separate strings. Then a file with name .UL command is sought; .UL command may be a path name including the ``/'' character to specify any file in the system. If .UL 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. .PP If file .UL command cannot be found, the \&shell generally prefixes a string such as .UL /\|bin\|/ to .UL command and attempts again to find the file. Directory .UL /\|bin contains commands intended to be generally used. (The sequence of directories to be searched may be changed by user request.) .SH 6.1 Standard I/O .PP The discussion of I/O in Section III above seems to imply that every file used by a program must be opened or created by the program in order to get a file descriptor for the file. Programs executed by the \&shell, however, start off with three open files with file descriptors 0, 1, and 2. As such a program begins execution, file 1 is open for writing, and is best understood as the standard output file. Except under circumstances indicated below, this file is the user's terminal. Thus programs that wish to write informative information ordinarily use file descriptor 1. Conversely, file 0 starts off open for reading, and programs that wish to read messages typed by the user read this file. .PP The \&shell is able to change the standard assignments of these file descriptors from the user's terminal printer and keyboard. If one of the arguments to a command is prefixed by ``>'', file descriptor 1 will, for the duration of the command, refer to the file named after the ``>''. For example: .P1 ls .P2 ordinarily lists, on the typewriter, the names of the files in the current directory. The command: .P1 ls >there .P2 creates a file called .UL there and places the listing there. Thus the argument .UL >there means ``place output on .UL there .'' On the other hand: .P1 ed .P2 ordinarily enters the editor, which takes requests from the user via his keyboard. The command .P1 ed