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

📄 bash.1

📁 android-w.song.android.widget
💻 1
📖 第 1 页 / 共 5 页
字号:
.BR identifier ..TP.B metacharacterA character that, when unquoted, separates words.  One of the following:.br.RS.PP.if t \fB|  &  ;  (  )  <  >  space  tab\fP.if n \fB|  & ; ( ) < > space tab\fP.RE.PP.TP.B control operatorA \fItoken\fP that performs a control function.  It is one of the followingsymbols:.RS.PP.if t \fB||  &  &&  ;  ;;  (  )  |  |&    <newline>\fP.if n \fB|| & && ; ;; ( ) | |& <newline>\fP.RE.PD.SH "RESERVED WORDS"\fIReserved words\fP are words that have a special meaning to the shell.The following words are recognized as reserved when unquoted and eitherthe first word of a simple command (see.SM.B SHELL GRAMMARbelow) or the third word of a .B case or.B forcommand:.if t .RS.PP.B.if n ! case  do done elif else esac fi for function if in select then until while { } time [[ ]].if t !    case    do    done    elif    else    esac    fi    for    function    if    in    select    then    until    while    {    }    time    [[    ]].if t .RE.SH "SHELL GRAMMAR".SS Simple Commands.PPA \fIsimple command\fP is a sequence of optional variable assignmentsfollowed by \fBblank\fP-separated words and redirections, andterminated by a \fIcontrol operator\fP.  The first wordspecifies the command to be executed, and is passed as argument zero.The remaining words are passed as arguments to the invoked command..PPThe return value of a \fIsimple command\fP is its exit status, or128+\fIn\^\fP if the command is terminated by signal.IR n ..SS Pipelines.PPA \fIpipeline\fP is a sequence of one or more commands separated byone of the control operators.B |or \fB|&\fP.The format for a pipeline is:.RS.PP[\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand\fP [ [\fB|\fP\(bv\fB|&\fP] \fIcommand2\fP ... ].RE.PPThe standard output of.I commandis connected via a pipe to the standard input of.IR command2 .This connection is performed before any redirections specified by thecommand (see.SM.B REDIRECTIONbelow).If \fB|&\fP is used, the standard error of \fIcommand\fP is connected to\fIcommand2\fP's standard input through the pipe; it is shorthand for\fB2>&1 |\fP.This implicit redirection of the standard error is performed after anyredirections specified by the command..PPThe return status of a pipeline is the exit status of the lastcommand, unless the \fBpipefail\fP option is enabled.If \fBpipefail\fP is enabled, the pipeline's return status is thevalue of the last (rightmost) command to exit with a non-zero status,or zero if all commands exit successfully.If the reserved word.B !precedes a pipeline, the exit status of that pipeline is the logicalnegation of the exit status as described above.The shell waits for all commands in the pipeline toterminate before returning a value..PPIf the.B timereserved word precedes a pipeline, the elapsed as well as user andsystem time consumed by its execution are reported when the pipelineterminates.The \fB\-p\fP option changes the output format to that specified by POSIX.When the shell is in \fIposix mode\fP, it does not recognize\fBtime\fP as a reserved word if the next token begins with a `-'.The.SM.B TIMEFORMATvariable may be set to a format string that specifies how the timinginformation should be displayed; see the description of.SM.B TIMEFORMATunder.B "Shell Variables"below..PPWhen the shell is in \fIposix mode\fP, \fBtime\fPmay be followed by a newline.  In this case, the shell displays thetotal user and system time consumed by the shell and its children.The.SM.B TIMEFORMATvariable may be used to specify the format ofthe time information..PPEach command in a pipeline is executed as a separate process (i.e., in asubshell)..SS Lists.PPA \fIlist\fP is a sequence of one or more pipelines separated by oneof the operators.BR ; ,.BR & ,.BR && ,or.BR || ,and optionally terminated by one of.BR ; ,.BR & ,or.BR <newline> ..PPOf these list operators,.B &&and.B ||have equal precedence, followed by.B ;and.BR & ,which have equal precedence..PPA sequence of one or more newlines may appear in a \fIlist\fP insteadof a semicolon to delimit commands..PPIf a command is terminated by the control operator.BR & ,the shell executes the command in the \fIbackground\fPin a subshell.  The shell does not wait for the command tofinish, and the return status is 0.  Commands separated by a.B ;are executed sequentially; the shell waits for eachcommand to terminate in turn.  The return status is theexit status of the last command executed..PPAND and OR lists are sequences of one of more pipelines separated by the\fB&&\fP and \fB||\fP control operators, respectively.AND and OR lists are executed with left associativity.An AND list has the form.RS.PP\fIcommand1\fP \fB&&\fP \fIcommand2\fP.RE.PP.I command2is executed if, and only if,.I command1returns an exit status of zero..PPAn OR list has the form.RS.PP\fIcommand1\fP \fB||\fP \fIcommand2\fP.PP.RE.PP.I command2is executed if and only if.I command1returns a non-zero exit status.The return status ofAND and OR lists is the exit status of the last commandexecuted in the list..SS Compound Commands.PPA \fIcompound command\fP is one of the following:.TP(\fIlist\fP)\fIlist\fP is executed in a subshell environment (see.SM\fBCOMMAND EXECUTION ENVIRONMENT\fPbelow).Variable assignments and builtincommands that affect the shell's environment do not remain in effectafter the command completes.  The return status is the exit status of\fIlist\fP..TP{ \fIlist\fP; }\fIlist\fP is simply executed in the current shell environment.\fIlist\fP must be terminated with a newline or semicolon.This is known as a \fIgroup command\fP.The return status is the exit status of\fIlist\fP.Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and\fB}\fP are \fIreserved words\fP and must occur where a reservedword is permitted to be recognized.  Since they do not cause a wordbreak, they must be separated from \fIlist\fP by whitespace or anothershell metacharacter..TP((\fIexpression\fP))The \fIexpression\fP is evaluated according to the rules describedbelow under.SM.BR "ARITHMETIC EVALUATION" .If the value of the expression is non-zero, the return status is 0;otherwise the return status is 1.  This is exactly equivalent to\fBlet "\fIexpression\fP"\fR..TP\fB[[\fP \fIexpression\fP \fB]]\fPReturn a status of 0 or 1 depending on the evaluation ofthe conditional expression \fIexpression\fP.Expressions are composed of the primaries described below under.SM.BR "CONDITIONAL EXPRESSIONS" .Word splitting and pathname expansion are not performed on the wordsbetween the \fB[[\fP and \fB]]\fP; tilde expansion, parameter andvariable expansion, arithmetic expansion, command substitution, processsubstitution, and quote removal are performed.Conditional operators such as \fB\-f\fP must be unquoted to be recognizedas primaries..if t .sp 0.5.if n .sp 1When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sortlexicographically using the current locale..if t .sp 0.5.if n .sp 1When the \fB==\fP and \fB!=\fP operators are used, the string to theright of the operator is considered a pattern and matched accordingto the rules described below under \fBPattern Matching\fP.If the shell option.B nocasematchis enabled, the match is performed without regard to the caseof alphabetic characters.The return value is 0 if the string matches (\fB==\fP) or does not match(\fB!=\fP) the pattern, and 1 otherwise.Any part of the pattern may be quoted to force it to be matched as astring..if t .sp 0.5.if n .sp 1An additional binary operator, \fB=~\fP, is available, with the sameprecedence as \fB==\fP and \fB!=\fP.When it is used, the string to the right of the operator is consideredan extended regular expression and matched accordingly (as in \fIregex\fP(3)).  The return value is 0 if the string matchesthe pattern, and 1 otherwise.If the regular expression is syntactically incorrect, the conditionalexpression's return value is 2.If the shell option.B nocasematchis enabled, the match is performed without regard to the caseof alphabetic characters.Any part of the pattern may be quoted to force it to be matched as astring.Substrings matched by parenthesized subexpressions within the regularexpression are saved in the array variable.SM.BR BASH_REMATCH .The element of.SM.B BASH_REMATCHwith index 0 is the portion of the stringmatching the entire regular expression.The element of.SM.B BASH_REMATCHwith index \fIn\fP is the portion of thestring matching the \fIn\fPth parenthesized subexpression..if t .sp 0.5.if n .sp 1Expressions may be combined using the following operators, listedin decreasing order of precedence:.if t .sp 0.5.if n .sp 1.RS.PD 0.TP.B ( \fIexpression\fP )Returns the value of \fIexpression\fP.This may be used to override the normal precedence of operators..TP.B ! \fIexpression\fPTrue if.I expressionis false..TP\fIexpression1\fP \fB&&\fP \fIexpression2\fPTrue if both.I expression1and.I expression2are true..TP\fIexpression1\fP \fB||\fP \fIexpression2\fPTrue if either.I expression1or.I expression2is true..PD.LPThe \fB&&\fP and \fB||\fPoperators do not evaluate \fIexpression2\fP if the value of\fIexpression1\fP is sufficient to determine the return value ofthe entire conditional expression..RE.TP\fBfor\fP \fIname\fP [ [ \fBin\fP [ \fIword ...\fP ] ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fPThe list of words following \fBin\fP is expanded, generating a listof items.The variable \fIname\fP is set to each element of this listin turn, and \fIlist\fP is executed each time.If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes\fIlist\fP once for each positional parameter that is set (see.SM.B PARAMETERSbelow).The return status is the exit status of the last command that executes.If the expansion of the items following \fBin\fP results in an emptylist, no commands are executed, and the return status is 0..TP\fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fPFirst, the arithmetic expression \fIexpr1\fP is evaluated accordingto the rules described below under.SM.BR "ARITHMETIC EVALUATION" .The arithmetic expression \fIexpr2\fP is then evaluated repeatedlyuntil it evaluates to zero.Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP isexecuted and the arithmetic expression \fIexpr3\fP is evaluated.If any expression is omitted, it behaves as if it evaluates to 1.The return value is the exit status of the last command in \fIlist\fPthat is executed, or false if any of the expressions is invalid..TP\fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fPThe list of words following \fBin\fP is expanded, generating a listof items.  The set of expanded words is printed on the standarderror, each preceded by a number.  If the \fBin\fP\fIword\fP is omitted, the positional parameters are printed (see.SM.B PARAMETERSbelow).  The.SM.B PS3prompt is then displayed and a line read from the standard input.If the line consists of a number corresponding to one ofthe displayed words, then the value of.I nameis set to that word.  If the line is empty, the words and promptare displayed again.  If EOF is read, the command completes.  Anyother value read causes.I nameto be set to null.  The line read is saved in the variable.SM.BR REPLY .The.I listis executed after each selection until a.B breakcommand is executed.The exit status of.B selectis the exit status of the last command executed in.IR list ,or zero if no commands were executed..TP\fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \... ) \fIlist\fP ;; ] ... \fBesac\fPA \fBcase\fP command first expands \fIword\fP, and tries to matchit against each \fIpattern\fP in turn, using the same matching rulesas for pathname expansion (see.B Pathname Expansionbelow).The \fIword\fP is expanded using tildeexpansion, parameter and variable expansion, arithmetic substitution,command substitution, process substitution and quote removal.Each \fIpattern\fP examined is expanded using tildeexpansion, parameter and variable expansion, arithmetic substitution,command substitution, and process substitution.If the shell option.B nocasematchis enabled, the match is performed without regard to the caseof alphabetic characters.When a match is found, the corresponding \fIlist\fP is executed.If the \fB;;\fP operator is used, no subsequent matches are attempted afterthe first pattern match.Using \fB;&\fP in place of \fB;;\fP causes execution to continue withthe \fIlist\fP associated with the next set of patterns.Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the nextpattern list in the statement, if any, and execute any associated \fIlist\fPon a successful match.The exit status is zero if nopattern matches.  Otherwise, it is the exit status of thelast command executed in \fIlist\fP..TP\fBif\fP \fIlist\fP; \fBthen\fP \fIlist;\fP \[ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \[ \fBelse\fP \fIlist\fP; ] \fBfi\fPThe.B if .I listis executed.  If its exit status is zero, the\fBthen\fP \fIlist\fP is executed.  Otherwise, each \fBelif\fP\fIlist\fP is executed in turn, and if its exit status is zero,the corresponding \fBthen\fP \fIlist\fP is executed and thecommand completes.  Otherwise, the \fBelse\fP \fIlist\fP isexecuted, if present.  The exit status is the exit status of thelast command executed, or zero if no condition tested true..TP\fBwhile\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP.PD 0.TP\fBuntil\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP.PDThe \fBwhile\fP command continuously executes the list\fIlist-2\fP as long as the last command in the list \fIlist-1\fP returnsan exit status of zero.  The \fBuntil\fP command is identicalto the \fBwhile\fP command, except that the test is negated;.I list-2is executed as long as the last command in.I list-1returns a non-zero exit status.The exit status of the \fBwhile\fP and \fBuntil\fP commandsis the exit statusof the last command executed in \fIlist-2\fP, or zero ifnone was executed..SS Coprocesses.PPA \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reservedword.A coprocess is executed asynchronously in a subshell, as if the commandhad been terminated with the \fB&\fP control operator, with a two-way pipeestablished between the executing shell and the coprocess..PPThe format for a coprocess is:.RS.PP\fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP].RE.PPThis creates a coprocess named \fINAME\fP.If \fINAME\fP is not supplied, the default name is \fICOPROC\fP.\fINAME\fP must not be supplied if \fIcommand\fP is a \fIsimplecommand\fP (see above); otherwise, it is interpreted as the first wordof the simple command.When the coproc is executed, the shell creates an array variable (see.B Arraysbelow) named \fINAME\fP in the context of the executing shell.The standard output of.I command

⌨️ 快捷键说明

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