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

📄 ash.1

📁 操作系统设计与实现源码
💻 1
📖 第 1 页 / 共 3 页
字号:
will consist of any arguments given on the first line of the program,followed by the name of the program, followed by the arguments passedto the program..h "Redirection"Input/output redirections can be intermixed with the words in a simplecommand and can be placed following any of the other commands.  Whenredirection occurs, the shell saves the old values of the file descriptorsand restores them when the command completes.  The ``<'', ``>'', and ``>>''redirections open a file for input, output, and appending, respectively.The ``<&digit'' and ``>&digit'' makes the input or output a duplicateof the file descriptor numbered by the digit.  If a minus sign is usedin place of a digit, the standard input or standard output are closed..PPThe ``<<\ word'' redirectiontakes input from a.I heredocument.As the shell encounters ``<<'' redirections, it collects them.  Thenext time it encounters an unescaped newline, it reads the documentsin turn.  The word following the ``<<'' specifies the contents of theline that terminates the document.  If none of the quoting methods('', "", or \e) are used to enter the word, then the document is treatedlike a word inside double quotes:  ``$'' and backquote are expandedand backslash can be used to escape these and to continue long lines.The word cannot contain any variable or command substitutions, andits length (after quoting) must be in the range of 1 to 79 characters.If ``<<-'' is used in place of ``<<'', then leading tabs are deletedfrom the lines of the document.  (This is to allow you do indent shellprocedures containing here documents in a natural fashion.).PPAny of the preceding redirection operators may be preceded by a singledigit specifying the file descriptor to be redirected.  There cannotbe any white space between the digit and the redirection operator..h "Path Search"When locating a command, the shell first looks to see if it has ashell function by that name.  Then, if PATH does not contain anentry for "%builtin", it looks for a builtin command by that name.Finally, it searches each entry in PATH in turn for the command..PPThe value of the PATH variable should be a series of entries separatedby colons.Each entry consists of a directory name, or a directory name followedby a flag beginning with a percent sign.The current directory should be indicated by an empty directory name..PPIf no percent sign is present, then the entry causes the shell tosearch for the command in the specified directory.  If the flag is``%builtin'' then the list of shell builtin commands is searched.If the flag is ``%func'' then the directory is searched for a file whichis read as input to the shell.  This file should define a functionwhose name is the name of the command being searched for..PPCommand names containing a slash are simply executed without performingany of the above searches..h "The Environment"The environment of a command is a set of name/value pairs.  When theshell is invoked, it reads these names and values, sets the shellvariables with these names to the corresponding values, and marksthe variables as exported.  The.I exportcommand can be used to mark additional variables as exported..PPThe environment of a command is constructed by constructing name/valuepairs from all the exported shell variables, and then modifying thisset by the assignments which precede the command, if any..h "Expansion"The process of evaluating words when a shell procedure is executed iscalled.IR expansion .Expansion consists of four steps:  variable substitution, commandsubstitution, word splitting, and file name generation.  If a wordis the expression following the word.B casein a case statement, the file namewhich follows a redirection symbol, or an assignment to the environmentof a command, then the word cannot be split into multiple words.  Inthese cases, the last two steps of the expansion process are omitted..h "Variable Substitution"To be written..h "Command Substitution".I Ashaccepts two syntaxes for command substitution:.d`\fIlist\fR`.eand.d$(\fIlist\fR).eEither of these may be included in a word.During the command substitution process, the command (syntactly a.IR list )will be executed and anything that the command writes to the standardoutput will be captured by the shell.  The final newline (if any) ofthe output will be deleted; the rest of the output will be substitutedfor the command in the word..h "Word Splitting"When the value of a variable or the output of a command is substituted,the resulting text is subject to word splitting, unless the dollar signintroducing the variable or backquotes containing the text were enclosedin double quotes.  In addition, ``$@'' is subject to a special type ofsplitting, even in the presence of double quotes..PPAsh uses two different splitting algorithms.  The normal approach, whichis intended for splitting text separated by which space, is used if thefirst character of the shell variable IFS is a space.  Otherwise an alternativeexperimental algorithm, which is useful for splitting (possibly empty)fields separated by a separator character, is used..PPWhen performing splitting, the shell scans the replacement text lookingfor a character (when IFS does not begin with a space) or a sequence ofcharacters (when IFS does begin with a space), deletes the character orsequence of characters, and spits the word into two strings at thatpoint.  When IFS begins with a space, the shell deletes either of thestrings if they are null.  As a special case, if the word containingthe replacement text is the null string, the word is deleted..PPThe variable ``$@'' is special in two ways.  First, splitting takesplace between the positional parameters, even if the text is enclosedin double quotes.  Second, if the word containing the replacementtext is the null string and there are no positional parameters, thenthe word is deleted.  The result of these rules is that "$@" isequivalent to "$1" "$2" ... "$\fIn\fR", where \fIn\fR is the number ofpositional parameters.  (Note that this differs from the System V shell.The System V documentation claims that "$@" behaves this way; in facton the System V shell "$@" is equivalent to "" when there are nopositional paramteters.).h "File Name Generation"Unless the.B -fflag is set, file name generation is performed after word splitting iscomplete.  Each word is viewed as a series of patterns, separated byslashes.  The process of expansion replaces the word with the names ofall existing files whose names can be formed by replacing each patternwith a string that matches the specified pattern.  There are tworestrictions on this:  first, a pattern cannot match a string containinga slash, and second, a pattern cannot match a string starting with aperiod unless the first character of the pattern is a period..PPIf a word fails to match any files and the.B -zflag is not set, then the word will be left unchanged (except that themeta-characters will be converted to normal characters).  If the.B -zflag is set, then the word is only left unchanged if noneof the patterns contain a character that can match anything besidesitself.  Otherwise the.B -zflag forces the word to be replaced with the names of the files that itmatches, even if there are zero names..h "Patterns"A.I patternconsists of normal characters, which match themselves, and meta-characters.The meta-characters are ``!'', ``*'', ``?'', and ``[''.  These characters losethere special meanings if they are quoted.  When command or variablesubstitution is performed and the dollar sign or back quotes are notdouble quoted, the value of the variable or the output of the commandis scanned for these characters and they are turned into meta-characters..PPTwo exclamation points at the beginning of a pattern function as a ``not''operator, causing the pattern to match any string that the remainder ofthe pattern does.I notmatch.  Other occurances of exclamation points in a pattern matchexclamation points.  Two exclamation points are required rather than oneto decrease the incompatibility with the System V shell (which does nottreat exclamation points specially)..PPAn asterisk (``*'') matches any string of characters.A question mark matches any single character.A left bracket (``['') introduces a character class.  The end of thecharacter class is indicated by a ``]''; if the ``]'' is missing thenthe ``['' matches a ``['' rather than introducing a character class.A character class matches any of the characters between the squarebrackets.  A range of characters may be specified using a minus sign.The character class may be complemented by making an exclamation pointthe first character of the character class..PPTo include a ``]'' in a character class, make it the first character listed(after the ``!'', if any).To include a minus sign, make it the first or last character listed..h "The /u Directory"By convention, the name ``/u/user'' refers to the home directory of thespecified user.  There are good reasons why this feature should be supportedby the file system (using a feature such as symbolic links) rather thanby the shell, but.I ashis capable of performing this mapping if the file system doesn't.If the mapping is done by.IR ash ,setting the.B -fflag will turn it off..h "Character Set".I Ashsilently discards nul characters.  Any other character will be handledcorrectly by.IR ash ,including characters with the high order bit set..h "Job Names and Job Control"The term.I jobrefers to a process created by a shell command, or in the case of apipeline, to the set of processes in the pipeline.  The ways to referto a job are:.d%\fInumber\fR%\fIstring\fR%%\fIprocess_id\fR.eThe first form identifies a job by job number.When a command is run,.I ashassigns it a job number(the lowest unused number is assigned).The second form identifies a job by giving a prefix of the command usedto create the job.  The prefix must be unique.  If there is only one job,then the null prefix will identify the job, so you can refer to the jobby writing ``%''.  The third form refers to the \fIcurrent job\fR.  Thecurrent job is the last job to be stopped while it was in the foreground.(See the next paragraph.)  The last form identifies a job by giving theprocess id of the last process in the job..PPIf the operating system that.I ashis running on supports job control,.I ashwill allow you to use it.In this case, typing the suspend character (typically ^Z) while runninga command will return you to.I ashand will make the suspended command the current job.  You can then continuethe job in the background by typing.IR bg ,or you can continue it in the foreground by typing.IR fg ..h "Atty"If the shell variable ATTY is set, and the shell variable TERM is notset to ``emacs'', then \fIash\fR generates appropriate escape sequencesto talk to.IR atty (1)..h "Exit Statuses"By tradition, an exit status of zero means that a command has succeededand a nonzero exit status indicates that the command failed.  This isbetter than no convention at all, but in practice it is extremely usefulto allow commands that succeed to use the exit status to return informationto the caller.  A variety of better conventions have been proposed, butnone of them has met with universal approval.  The convention used by\fIash\fR and all the programs included in the \fIash\fR distribution isas follows:.ta 1i 2i.nf	0	Success.	1	Alternate success.	2	Failure.	129-...	Command terminated by a signal..fiThe \fIalternate success\fR return is used by commands to indicate variousconditions which are not errors but which can, with a little imagination,be conceived of as less successful than plain success.  For example,.I testreturns 1 when the tested condition is false and.I getoptsreturns 1 when there are no more options.Because this convention is not used universally, the.B -eoption of.I ashcauses the shell to exit when a command returns 1 even though thatcontradicts the convention described here..PPWhen a command is terminated by a signal, the uses 128 plus the signalnumber as the exit code for the command..h "Builtin Commands"This concluding section lists the builtin commands which are builtinbecause they need to perform some operation that can't be performed by aseparate process.  In addition to these, there are several other commands.RI ( catf ,.IR echo ,.IR expr ,.IR line ,.IR nlecho ,.IR test ,.RI  `` : '',and.IR true )which can optionally be compiled into the shell.  The builtincommands described below that accept options use the System V Release 2.IR getopt (3)syntax..sp.b bg[.I job] ....brContinue the specified jobs (or the current job if no jobs are given)in the background.This command is only available on systems with Bekeley job control..b command.IR "command arg" ....brExecute the specified builtin command.  (This is useful when you have ashell function with the same name as a builtin command.).b cd[.I directory].brSwitch to the specified directory (default $HOME).If the an entry for CDPATH appears in the environment of the cd commandor the shell variable CDPATH is set and the directory name does notbegin with a slash, then the directories listed in CDPATH will besearched for the specified directory.  The format of CDPATH is thesame as that of PATH.In an interactive shell, the cd command will print out the name of thedirectory that it actually switched to if this is different from thename that the user gave.  These may be different either becausethe CDPATH mechanism was used or because a symbolic link was crossed..\" .b ".\fI\h'0.1i'file".\" Cawf can't do \h'0.1i'.b ..I file.brThe commands in the specified file are read and executed by the shell.A path search is not done to find the file because the directories inPATH generally contain files that are intended to be executed, not read..b eval.IR string ....brThe strings are parsed as shell commands and executed.(This differs from the System V shell, which concatenates the arguments(separated by spaces) and parses the result as a single command.).b exec[.IR "command arg" ...].brUnless.I commandis omitted,the shell process is replaced with the specified program (which must be a realprogram, not a shell builtin or function).Any redirections on the exec command are marked as permanent, so that theyare not undone when the exec command finishes.If the command is not found, the exec command causes the shell to exit..b exit[.I exitstatus].brTerminate the shell process.  If.I exitstatusis given it is used as theexit status of the shell; otherwise the exit status of the precedingcommand is used..b export.IR name ....brThe specified names are exported so that they will appear in the environmentof subsequent commands.  The only way to un-export a variable is to unset it..I Ashallows the value of a variable to be set at the same time it is exportedby writing.d\fBexport\fR name=value.eWith no arguments the export command lists the names of all exported variables..b fg[.I job].br

⌨️ 快捷键说明

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