⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sh.1

📁 UNIX v6源代码 这几乎是最经典的unix版本 unix操作系统设计和莱昂氏unix源代码分析都是用的该版
💻 1
字号:
.th SH I 5/15/74.sh NAMEsh  \*-  shell (command interpreter).sh SYNOPSIS.bd sh[.bd \*-t] [.bd \*-c][ name [ arg1 ... [ arg9 ] ] ].sh DESCRIPTION.it Shis the standard command interpreter.It is the program which reads and arranges the execution ofthe command lines typed by most users.It may itself be called as a command to interpretfiles of commands.Before discussing the arguments to the Shellused as a command, the structure of commandlines themselves will be given..s3.bd "Commands."Each command is a sequence of non-blank command argumentsseparated by blanks.Thefirst argument specifies the name of a command to beexecuted.Except for certain types of specialarguments discussed below, the argumentsother than the command name are passedwithout interpretation to the invokedcommand..s3If the first argument is the name of an executablefile, 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 attemptis made to execute the resultingfile.(Certain lesser-used commandslive in `/usr/bin'.).s3If 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 commandsand a new Shell is created to execute it.See ``Argument passing'' below..s3If the file cannot be found,a diagnostic is printed..s3.bd "Command lines."One or more commands separated by `|' or `^' constitute achain of.it filters.The standard output of each command but the lastis takenas the standard input of the next command.Each command is run as a separate process, connectedby pipes (see pipe(II)) to its neighbors.A command line contained inparentheses `( )' may appear in place of a simple commandas a filter..s3A.it "command line"consists of one ormore pipelines separated, and perhaps terminated by `\fB;\fR' or `&'.The semicolon designates sequential execution.The ampersand causes the preceding pipeline to be executedwithout waiting for it to finish.The process id of such a pipeline is reported, so thatit may be used if necessary for a subsequent.it waitor.it kill..s3.bd "Termination Reporting."If a command (not followed by `&') terminates abnormally,a message is printed.(All terminations other than exit and interruptare considered abnormal.)Termination reports for commands followed by `&'are given upon receipt of the firstcommand subsequent to the termination ofthe command,or when a.it waitis executed.The following is a list of the abnormaltermination messages:.s3.nf	Bus error	Trace/BPT trap	Illegal instruction	IOT trap	EMT trap	Bad system call	Quit	Floating exception	Memory violation	Killed	Broken Pipe.s3.fiIf a core image is produced,`\*- Core dumped' is appended to the appropriate message..s3.bd "Redirection of I/O."There are three character sequences that cause the immediately following stringto be interpreted as a special argument to the Shell itself.Such an argument mayappear anywhere amongthe arguments of a simple command, or before or aftera parenthesized command list, and is associated with thatcommand or command list..s3An argument of the form `<arg' causes the file`arg'to be used as the standard input (file descriptor 0) of the associated command..s3An argument of the form `>arg' causes file `arg' to be usedas the standard output (file descriptor 1) for the associated command.`Arg' is created if it did not exist, and in any case is truncatedat the outset..s3An argument of the form `>>arg' causes file `arg' to be used as thestandard 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..s3For example, either of the command lines.s3	ls >junk; cat tail >>junk.br	( ls; cat tail ) >junk.s3creates, on file `junk', a listing of the working directory, followed immediatelyby the contents of file `tail'..s3Either of the constructs `>arg' or `>>arg'associated with any but the last command of a pipelineis ineffectual, as is `<arg' in any but the first..s3In commands called by the Shell,file descriptor 2 refers to the standard output of theShell before any redirection.Thus filters may write diagnosticsto a locationwhere they have a chance to be seen..s3.bd "Generation of argument lists."If any argument contains any of the characters `?',`*' or `[', it is treated specially as follows.The current directory is searched for files which.it matchthe given argument..s3The character `*' in an argument matches any string of charactersin a file name (including the null string)..s3The character `?' matches anysingle character in a file name..s3Square brackets `[...]' specifya class of characters whichmatches any single file-name character in the class.Within the brackets,each ordinary character is takento be a member of the class.A pair of characters separated by `\*-' placesin the classeach character lexically greater than or equal tothe first and less than or equal to the secondmember of the pair..s3Other characters match only the same character inthe file name..s3For example, `*' matches all file names;`?' matches all one-character file names; `[ab]*.s' matchesall file names beginning with `a' or `b' and ending with `.s';`?[zi\*-m]' matches all two-character file names endingwith `z' or the letters `i' through `m'..s3If the argument with `*' or `?' also contains a `/', a slightlydifferent procedure is used:  instead of the current directory,the directory used is the one obtainedby taking the argument up to the last `/' before a `*' or `?'.The matching process matches the remainder of the argumentafter this `/' against the files in the derived directory.For example: `/usr/dmr/a*.s' matchesall files in directory `/usr/dmr' which beginwith `a' and end with `.s'..s3In any event, a list of names is obtained which matchthe argument.This list is sorted into alphabetical order,and the resulting sequence of arguments replaces thesingle argument containing the `*', `[', or `?'.The same process is carried out for each argument(the resulting lists are.it notmerged)and finally the command is called with the resulting list ofarguments..s3.bd "Quoting."The character `\\' causes the immediately following characterto lose any special meaning it may have to the Shell;  in thisway `<', `>', and other characters meaningful to theShell may be passed as part of arguments.A special case of this feature allows the continuation of commandsonto more than one line:  a new-line preceded by `\\' is translatedinto a blank..s3Sequences of characters enclosed in double (") or single (\*a)quotes are also taken literally.For example:.s3	ls  |  pr \*-h "My directory".s3causes a directory listing to be producedby.it ls,and passed on to.it prto beprinted with the heading `My directory'.Quotes permit the inclusion of blanks inthe heading, which is a single argument to.it pr..s3.bd "Argument passing."When the Shell is invoked as a command, it has additionalstring processing capabilities.Recall that the form in which the Shell is invoked is.s3	sh [ name [ arg1 ... [ arg9 ] ] ].s3The.it nameis the name of a file which is read andinterpreted.If not given, this subinstance of the Shellcontinues to read the standard input file..s3In command lines in the file(not in command input),character sequences of the form `$n', where.it nis a digit,are replaced by the\fIn\fRth argument to the invocationof the Shell (argn).`$0' is replaced by.it name..s3The argument `\*-t,' used alone, causes.it shto read the standard input for a single line, executeit as a command, and then exit.This facility replaces the older `mini-shell.'It is useful for interactive programswhich allow users to executesystem commands..s3The argument `\*-c' (used with one following argument)causes the next argument to be taken as a commandline and executed.No new-line need be present, but new-line charactersare treated appropriately.This facility is useful as an alternative to`\*-t' where the caller has already readsome of the characters of the command to be executed..s3.bd "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 tolog out from UNIX is to type an EOT..s3.bd "Special commands."The following commands are treated specially by the Shell..s3.it chdiris done withoutspawning a new process by executing.it "sys chdir"(II)..s3.it loginis done by executing/bin/login without creating a new process..s3.it waitis done without spawning a new process byexecuting.it "sys wait"(II)..s3.it shiftis done by manipulating the argumentsto the Shell..s3`\fB:\fR' is simply ignored..s3.bd "Command file errors; interrupts."Any Shell-detected error, or an interrupt signal,during the execution of a command filecauses the Shell to cease execution of that file..s3Processes that are created with `&' ignore interrupts.Also if such a process has not redirected itsinput with a `<',its input is automatically redirected to thezero 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 theShell..brchdir (I), login (I), wait (I), shift (I).sh BUGSThere is no way to redirect the diagnostic output.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -