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

📄 ksh.man

📁 一个开放源代码的 AT&T 的 Korn Shell 的复制品, 支持大多数 ksh89 的特性。
💻 MAN
📖 第 1 页 / 共 5 页
字号:
of \fBin\fP and \fBesac\fP (\fIe.g.\fP, \fBcase $foo { *) echo bar; }\fP).The exit status of a \fBcase\fP statement is that of the executed \fIlist\fP;if no \fIlist\fP is executed, the exit status is zero..\"}}}.\"{{{  for name [ in word ... term ] do list done.IP "\fBfor\fP \fIname\fP [ \fBin\fP \fIword\fP ... \fIterm\fP ] \fBdo\fP \fIlist\fP \fBdone\fP"where \fIterm\fP is either a newline or a \fB;\fP.For each \fIword\fP in the specified word list, the parameter \fIname\fP isset to the word and \fIlist\fP is executed.  If \fBin\fP is not used tospecify a word list, the positional parameters (\fB"$1"\fP, \fB"$2"\fP,\fIetc.\fP) are used instead.For historical reasons, open and close braces may be used insteadof \fBdo\fP and \fBdone\fP (\fIe.g.\fP, \fBfor i; { echo $i; }\fP).The exit status of a \fBfor\fP statement is the last exit statusof \fIlist\fP; if \fIlist\fP is never executed, the exit status is zero..\"}}}.\"{{{  if list then list [ elif list then list ] ... [ else list ] fi.IP "\fBif\fP \fIlist\fP \fBthen\fP \fIlist\fP [\fBelif\fP \fIlist\fP \fBthen\fP \fIlist\fP] ... [\fBelse\fP \fIlist\fP] \fBfi\fP"If the exit status of the first \fIlist\fP is zero, the second \fIlist\fPis executed; otherwise the \fIlist\fP following the \fBelif\fP, if any, isexecuted with similar consequences.  If all the lists following the \fBif\fPand \fBelif\fPs fail (\fIi.e.\fP, exit with non-zero status), the \fIlist\fPfollowing the \fBelse\fP is executed.The exit status of an \fBif\fP statement is thatof non-conditional \fIlist\fP that is executed; if no non-conditional\fIlist\fP is executed, the exit status is zero..\"}}}.\"{{{  select name [ in word ... ] do list done.ksh(.IP "\fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ... \fIterm\fP ] \fBdo\fP \fIlist\fP \fBdone\fP"where \fIterm\fP is either a newline or a \fB;\fP.The \fBselect\fP statement provides an automatic method of presentingthe user with a menu and selecting from it.An enumerated list of the specified \fIwords\fP is printed on standarderror, followed by a prompt (\fBPS3\fP, normally `\fB#? \fP').A number corresponding to one of the enumerated words is then readfrom standard input, \fIname\fP is set to the selected word (or isunset if the selection is not valid), \fBREPLY\fPis set to what was read (leading/trailing space is stripped),and \fIlist\fP is executed.If a blank line (\fIi.e.\fP, zero or more \fBIFS\fP characters) is entered,the menu is re-printed without executing \fIlist\fP.When \fIlist\fP completes, the enumerated list is printed if \fBREPLY\fPis null, the prompt is printed and so on.This process is continues until an end-of-file is read, an interrupt isreceived or a break statement is executed inside the loop.If \fBin\fP \fIword\fP \fB\&...\fP is omitted, the positional parametersare used (\fIi.e.\fP, \fB"$1"\fP, \fB"$2"\fP, \fIetc.\fP).For historical reasons, open and close braces may be used insteadof \fBdo\fP and \fBdone\fP (\fIe.g.\fP, \fBselect i; { echo $i; }\fP).The exit status of a \fBselect\fP statement is zero if a break statementis used to exit the loop, non-zero otherwise..ksh).\"}}}.\"{{{  until list do list done.IP "\fBuntil\fP \fIlist\fP \fBdo\fP \fIlist\fP \fBdone\fP"This works like \fBwhile\fP, except that the body is executed only while theexit status of the first \fIlist\fP is non-zero..\"}}}.\"{{{  while list do list done.IP "\fBwhile\fP \fIlist\fP \fBdo\fP \fIlist\fP \fBdone\fP"A \fBwhile\fP is a prechecked loop.  Its body is executed as oftenas the exit status of the first \fIlist\fP is zero.The exit status of a \fBwhile\fP statement is the last exit statusof the \fIlist\fP in the body of the loop; if the body is not executed,the exit status is zero..\"}}}.\"{{{  function name { list }.IP "\fBfunction\fP \fIname\fP \fB{\fP \fIlist\fP \fB}\fP"Defines the function \fIname\fP.See Functions below.Note that redirections specified after a function definition areperformed whenever the function is executed, not when the functiondefinition is executed..\"}}}.\"{{{  name () command.IP "\fIname\fP \fB()\fP \fIcommand\fP"Mostly the same as \fBfunction\fP.See Functions below..\"}}}.\"{{{  time [-p] [ pipeline ].IP "\fBtime\fP [ \fB-p\fP ] [ \fIpipeline\fP ]"The \fBtime\fP reserved word is described in the Command Execution section..\"}}}.\"{{{  (( expression )).ksh(.IP "\fB((\fP \fIexpression\fP \fB))\fP"The arithmetic expression \fIexpression\fP is evaluated;equivalent to \fBlet "\fP\fIexpression\fP\fB"\fP.See Arithmetic Expressions and the \fBlet\fP command below..ksh).\"}}}.\"{{{  [[ expression ]].ksh(.IP "\fB[[\fP \fIexpression\fP \fB]]\fP"Similar to the \fBtest\fP and \fB[\fP \&... \fB]\fP commands (described later),with the following exceptions:.RS.nr P2 \n(PD.nr PD 0.IP \ \ \(buField splitting and file name generation are not performed onarguments..IP \ \ \(buThe \fB\-a\fP (and) and \fB\-o\fP (or) operators are replaced with\fB&&\fP and \fB||\fP, respectively..IP \ \ \(buOperators (\fIe.g.\fP, \fB\-f\fP, \fB=\fP, \fB!\fP, \fIetc.\fP) must be unquoted..IP \ \ \(buThe second operand of \fB!=\fP and \fB=\fPexpressions are patterns (\fIe.g.\fP, the comparison in.ce\fB[[ foobar = f*r ]]\fPsucceeds)..IP \ \ \(buThere are two additional binary operators: \fB<\fP and \fB>\fPwhich return true if their first string operand is less than,or greater than, their second string operand, respectively..IP \ \ \(buThe single argument formof \fBtest\fP, which tests if the argument has non-zero length, is not valid- explicit operators must be always be used, \fIe.g.\fP, instead of.ce\fB[\fP \fIstr\fP \fB]\fPuse.ce\fB[[ \-n \fP\fIstr\fP\fB ]]\fP.IP \ \ \(buParameter, command and arithmetic substitutions are performed asexpressions are evaluated and lazy expression evaluation is used forthe \fB&&\fP and \fB||\fP operators.This means that in the statement.ce\fB[[ -r foo && $(< foo) = b*r ]]\fPthe \fB$(< foo)\fP is evaluated if and only if the file \fBfoo\fP existsand is readable..nr PD \n(P2.RE.ksh).\"}}}.\"}}}.\"}}}.\"{{{  Quoting.SS QuotingQuoting is used to prevent the shell from treating characters or wordsspecially.There are three methods of quoting: First, \fB\e\fP quotesthe following character, unless it is at the end of a line, in whichcase both the \fB\e\fP and the newline are stripped.Second, a single quote (\fB'\fP) quotes everything up to the next singlequote (this may span lines).Third, a double quote (\fB"\fP) quotes all characters,except \fB$\fP, \fB`\fP and \fB\e\fP, up to the next unquoted double quote.\fB$\fP and \fB`\fP inside double quotes have their usual meaning (\fIi.e.\fP,parameter, command or arithmetic substitution) except no field splittingis carried out on the results of double-quoted substitutions.If a \fB\e\fP inside a double-quoted string is followed by \fB\e\fP, \fB$\fP,\fB`\fP or \fB"\fP, it is replaced by the second character; if it isfollowed by a newline, both the \fB\e\fP and the newline are stripped;otherwise, both the \fB\e\fP and the character following are unchanged..PPNote: see POSIX Mode below for a special rule regarding sequencesof the form \fB"\fP...\fB`\fP...\fB\e"\fP...\fB`\fP..\fB"\fP..\"}}}.\"{{{  Aliases.SS "Aliases"There are two types of aliases: normal command aliases and trackedaliases.  Command aliases are normally used as a short hand for a longor often used command.  The shell expands command aliases (\fIi.e.\fP,substitutes the alias name for its value) when it reads the first wordof a command.  An expanded alias is re-processed to check for morealiases.  If a command alias ends in a space or tab, the following wordis also checked for alias expansion.  The alias expansion process stopswhen a word that is not an alias is found, when a quoted word is foundor when an alias word that is currently being expanded is found..PPThe following command aliases are defined automatically by the shell:.ft B.RS.ksh(autoload='typeset \-fu'.brfunctions='typeset \-f'.br.ksh)hash='alias \-t'.ksh(.brhistory='fc \-l'.brinteger='typeset \-i'.brlocal='typeset'.brlogin='exec login'.brnewgrp='exec newgrp'.brnohup='nohup '.brr='fc \-e \-'.brstop='kill \-STOP'.brsuspend='kill \-STOP $$'.ksh).brtype='whence \-v'.RE.ft P.PPTracked aliases allow the shell to remember where it found a particularcommand.  The first time the shell does a path search for a command thatis marked as a tracked alias, it saves the full path of the command.The next time the command is executed, the shell checks the saved pathto see that it is still valid, and if so, avoids repeating the pathsearch.  Tracked aliases can be listed and created using \fBalias\-t\fP.  Note that changing the \fBPATH\fP parameter clears the savedpaths for all tracked aliases.  If the \fBtrackall\fP option is set (\fIi.e.\fP,\fBset \-o trackall\fP or \fBset \-h\fP), the shell tracks allcommands.  This option is set automatically for non-interactive shells.For interactive shells, only the following commands are automaticallytracked: \fBcat\fP, \fBcc\fP, \fBchmod\fP, \fBcp\fP, \fBdate\fP, \fBed\fP,\fBemacs\fP, \fBgrep\fP, \fBls\fP, \fBmail\fP, \fBmake\fP, \fBmv\fP,\fBpr\fP, \fBrm\fP, \fBsed\fP, \fBsh\fP, \fBvi\fP and \fBwho\fP..\"}}}.\"{{{  Substitution.SS "Substitution"The first step the shell takes in executing a simple-command is toperform substitutions on the words of the command.There are three kinds of substitution: parameter, command and arithmetic.Parameter substitutions, which are described in detail in the next section,take the form \fB$name\fP or \fB${\fP...\fB}\fP; command substitutions takethe form \fB$(\fP\fIcommand\fP\fB)\fP or \fB`\fP\fIcommand\fP\fB`\fP;and arithmetic substitutions take the form \fB$((\fP\fIexpression\fP\fB))\fP..PPIf a substitution appears outside of double quotes, the results of thesubstitution are generally subject to word or field splitting according tothe current value of the \fBIFS\fP parameter.The \fBIFS\fP parameter specifies a list of characters which are used to break a string up into several words;any characters from the set space, tab and newline that appear in theIFS characters are called \fIIFS white space\fP.Sequences of one or more IFS white space characters, in combination withzero or one non-IFS white space characters delimit a field.As a special case, leading and trailing IFS white space is stripped (\fIi.e.\fP,no leading or trailing empty field is created by it); leading or trailingnon-IFS white space does create an empty field.Example: if \fBIFS\fP is set to `<space>:', the sequence of characters`<space>A<space>:<space><space>B::D' contains four fields: `A', `B', `' and `D'.Note that if the \fBIFS\fP parameter is set to the null string, nofield splitting is done; if the parameter is unset, the default valueof space, tab and newline is used..PPThe results of substitution are, unless otherwise specified, also subjectto brace expansion and file name expansion (see the relevant sectionsbelow)..PPA command substitution is replaced by the output generated by the specifiedcommand, which is run in a subshell.For \fB$(\fP\fIcommand\fP\fB)\fP substitutions, normal quoting rulesare used when \fIcommand\fP is parsed, however, for the\fB`\fP\fIcommand\fP\fB`\fP form, a \fB\e\fP followed by any of\fB$\fP, \fB`\fP or \fB\e\fP is stripped (a \fB\e\fP followed by any othercharacter is unchanged).As a special case in command substitutions, a command of the form\fB<\fP \fIfile\fP is interpreted to mean substitute the contentsof \fIfile\fP ($(< foo) has the same effect as $(cat foo), but itis carried out more efficiently because no process is started)..br.\"todo: fix this( $(..) parenthesis counting).NOTE: \fB$(\fP\fIcommand\fP\fB)\fP expressions are currently parsed byfinding the matching parenthesis, regardless of quoting.  This will hopefullybe fixed soon..PPArithmetic substitutions are replaced by the value of the specifiedexpression.For example, the command \fBecho $((2+3*4))\fP prints 14.See Arithmetic Expressions for a description of an \fIexpression\fP..\"}}}.\"{{{  Parameters.SS "Parameters"Parameters are shell variables; they can be assigned values andtheir values can be accessed using a parameter substitution.A parameter name is either one of the special single punctuation or digitcharacter parameters described below, or a letter followed by zero or moreletters or digits (`_' counts as a letter).The later form can be treated as arrays by appending an arrayindex of the form: \fB[\fP\fIexpr\fP\fB]\fP where \fIexpr\fP isan arithmetic expression.Array indicies are currently limited to the range 0 through 1023, inclusive.Parameter substitutions take the form \fB$\fP\fIname\fP,\fB${\fP\fIname\fP\fB}\fP or\fB${\fP\fIname\fP\fB[\fP\fIexpr\fP\fB]}\fP, where \fIname\fP is aparameter name.If substitution is performed on a parameter (or an array parameter element)that is not set, a nullstring is substituted unless the \fBnounset\fP option (\fBset \-o nounset\fPor \fBset \-u\fP) is set, in which case an error occurs..PP.\"{{{  parameter assignmentParameters can be assigned values in a number of ways.First, the shell implicitly sets some parameters like \fB#\fP, \fBPWD\fP,etc.; this is the only way the special single character parameters areset.Second, parameters are imported from the shell's environment at startup.Third, parameters can be assigned values on the command line, for example,`\fBFOO=bar\fP' sets the parameter FOO to bar; multiple parameterassignments can be given on a single command line and they canbe followed by a simple-command, in which case the assignments arein effect only for the duration of the command (such assignments arealso exported, see below for implications of this).Note that both the parameter name and the \fB=\fP must be unquoted for

⌨️ 快捷键说明

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