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

📄 ksh.man

📁 一个开放源代码的 AT&T 的 Korn Shell 的复制品, 支持大多数 ksh89 的特性。
💻 MAN
📖 第 1 页 / 共 5 页
字号:
.TPUnary operators:\fB+ \- ! ~ ++ --\fP.TPBinary operators:\fB,\fP.br\fB= *= /= %= += \-= <<= >>= &= ^= |=\fP.br\fB||\fP.br\fB&&\fP.br\fB|\fP.br\fB^\fP.br\fB&\fP.br\fB== !=\fP.br\fB< <= >= >\fP.br\fB<< >>\fP.br\fB+ \-\fP.br\fB* / %\fP.TPTernary operator:\fB?:\fP (precedence is immediately higher than assignment).TPGrouping operators:\fB( )\fP.PPInteger constants may be specified with arbitrary bases using the notation\fIbase\fP\fB#\fP\fInumber\fP, where \fIbase\fP is a decimal integer specifyingthe base, and \fInumber\fP is a number in the specified base..LPThe operators are evaluated as follows:.RS.IP "unary \fB+\fP"result is the argument (included for completeness)..IP "unary \fB\-\fP"negation..IP "\fB!\fP"logical not; the result is 1 if argument is zero, 0 if not..IP "\fB~\fP"arithmetic (bit-wise) not..IP "\fB++\fP"increment; must be applied to a parameter (not a literal or otherexpression) - the parameter is incremented by 1.When used as a prefix operator, the result is the incremented value ofthe parameter, when used as a postfix operator, the result is theoriginal value of the parameter..IP "\fB++\fP"similar to \fB++\fP, except the paramter is decremented by 1..IP "\fB,\fP"separates two arithmetic expressions; the left hand side is evaluated first,then the right.  The result is value of the expression on the right hand side..IP "\fB=\fP"assignment; variable on the left is set to the value on the right..IP "\fB*= /= %= += \-= <<= >>= &= ^= |=\fP"assignment operators; \fI<var> <op>\fP\fB=\fP \fI<expr>\fP is the same as\fI<var>\fP \fB=\fP \fI<var> <op>\fP \fB(\fP \fI<expr>\fP \fB)\fP..IP "\fB||\fP"logical or; the result is 1 if either argument is non-zero, 0 if not.The right argument is evaluated only if the left argument is zero..IP "\fB&&\fP"logical and; the result is 1 if both arguments are non-zero, 0 if not.The right argument is evaluated only if the left argument is non-zero..IP "\fB|\fP"arithmetic (bit-wise) or..IP "\fB^\fP"arithmetic (bit-wise) exclusive-or..IP "\fB&\fP"arithmetic (bit-wise) and..IP "\fB==\fP"equal; the result is 1 if both arguments are equal, 0 if not..IP "\fB!=\fP"not equal; the result is 0 if both arguments are equal, 1 if not..IP "\fB<\fP"less than; the result is 1 if the left argument is less than the right,0 if not..IP "\fB<= >= >\fP"less than or equal, greater than or equal, greater than.  See <..IP "\fB<< >>\fP"shift left (right); the result is the left argument with its bits shiftedleft (right) by the amount given in the right argument..IP "\fB+ - * /\fP"addition, subtraction, multiplication, and division..IP "\fB%\fP"remainder; the result is the remainder of the division of the left argumentby the right.  The sign of the result is unspecified if either argumentis negative..IP "\fI<arg1>\fP \fB?\fP \fI<arg2>\fP \fB:\fP \fI<arg3>\fP"if \fI<arg1>\fP is non-zero, the result is \fI<arg2>\fP,otherwise \fI<arg3>\fP..RE.\"}}}.\"{{{  Co-Processes.ksh(.SS "Co-Processes"A co-process, which is a pipeline created with the \fB|&\fP operator,is an asynchronous process that the shell can both write to(using \fBprint \-p\fP) and read from (using \fBread \-p\fP).The input and output of the co-process can also be manipulatedusing \fB>&p\fP and \fB<&p\fP redirections, respectively.Once a co-process has been started, another can't be started untilthe co-process exits, or until the co-process input has been redirected usingan \fBexec \fP\fIn\fP\fB>&p\fP redirection.If a co-process's input is redirected in this way, the next co-process to be started will share the output with the first co-process,unless the output of the initial co-process has been redirected using an\fBexec \fP\fIn\fP\fB<&p\fP redirection..PPSome notes concerning co-processes:.nr P2 \n(PD.nr PD 0.IP \ \ \(buthe only way to close the co-process input (so the co-process readsan end-of-file) is to redirect the input to a numbered file descriptorand then close that file descriptor (\fIe.g.\fP, \fBexec 3>&p;exec 3>&-\fP)..IP \ \ \(buin order for co-processes to share a common output, the shell must keepthe write portion of the output pipe open.This means that end of file will not be detected until all co-processessharing the co-process output have exited (when they all exit, the shellcloses its copy of the pipe).This can be avoided by redirecting the output to a numberedfile descriptor (as this also causes the shell to close its copy).Note that this behaviour is slightly different from the original Korn shellwhich closes its copy of the write portion of the co-processs output when themost recently started co-process (instead of when all sharing co-processes)exits..IP \ \ \(bu\fBprint \-p\fP will ignore SIGPIPE signals during writesif the signal is not being trapped or ignored; the same is not true ifthe co-process input has been duplicated to another file descriptor and\fBprint \-u\fP\fIn\fP is used..nr PD \n(P2.ksh).\"}}}.\"{{{  Functions.SS "Functions"Functions are defined using either Korn shell \fBfunction\fP \fIname\fPsyntax or the Bourne/POSIX shell \fIname\fP\fB()\fP syntax(see below for the difference between the two forms).Functions are like \fB.\fP-scripts in that they are executed inthe current environment, however, unlike \fB.\fP-scripts, shell arguments(\fIi.e.\fP, positional parameters, \fB$1\fP, \fIetc.\fP) are never visibleinside them.When the shell is determining the location of a command, functions aresearched after special built-in commands, and before regular and non-regularbuilt-ins, and before the \fBPATH\fP is searched..PPAn existing function may be deleted using \fBunset \-f\fP \fIfunction-name\fP.A list of functions can be obtained using \fBtypeset +f\fP and thefunction definitions can be listed using \fBtypeset \-f\fP.\fBautoload\fP (which is an alias for \fBtypeset \-fu\fP) may be used tocreate undefined functions; when an undefined function is executed, theshell searches the path specified in the \fBFPATH\fP parameter for a filewith the same name as the function, which, if found is read and executed.If after executing the file, the named function is found to be defined, thefunction is executed, otherwise, the normal command search is continued(\fIi.e.\fP, the shell searches the regular built-in command tableand \fBPATH\fP).Note that if a command is not found using \fBPATH\fP, an attempt ismade to autoload a function using \fBFPATH\fP (this is an undocumentedfeature of the original Korn shell)..PPFunctions can have two attributes, trace and export, which can be setwith \fBtypeset \-ft\fP and \fBtypeset \-fx\fP, respectively.When a traced function is executed, the shell's \fBxtrace\fP option is turnedon for the functions duration, otherwise the \fBxtrace\fP option is turned off.The export attribute of functions is currently not used.  In the originalKorn shell, exported functions are visible to shell scripts that are executed..PPSince functions are executed in the current shell environment, parameterassignments made inside functions are visible after the function completes.If this is not the desired effect, the \fBtypeset\fP command can be usedinside a function to create a local parameter.Note that special parameters (\fIe.g.\fP, \fB$$\fP, \fB$!\fP) can't bescoped in this way..PPThe exit status of a function is that of the last command executed inthe function.A function can be made to finish immediately using the \fBreturn\fP command;this may also be used to explicitly specify the exit status..PPFunctions defined with the \fBfunction\fP reserved word aretreated differently in the following ways from functions defined withthe \fB()\fP notation:.nr P2 \n(PD.nr PD 0.IP \ \ \(buthe \fB$0\fP parameter is set to the name of the function(Bourne-style functions leave \fB$0\fP untouched)..IP \ \ \(buparameter assignments preceeding function calls are not kept inthe shell environment(executing Bourne-style functions will keep assignments)..IP \ \ \(bu\fBOPTIND\fP is saved/reset and restored on entry and exit from the functionso \fBgetopts\fP can be used properly both inside and outside the function(Bourne-style functions leave \fBOPTIND\fP untouched, so using \fBgetopts\fPinside a function interferes with using \fBgetopts\fP outside the function)..nr PD \n(P2In the future, the following differences will also be added:.nr P2 \n(PD.nr PD 0.IP \ \ \(buA separate trap/signal environment will be used during the execution offunctions.This will mean that traps set inside a function will not affect the shell'straps and signals that are not ignored in the shell (but may be trapped) willhave their default effect in a function..IP \ \ \(buThe EXIT trap, if set in a function, will be executed after the functionreturns..nr PD \n(P2.\"}}}.\"{{{  POSIX mode.SS "POSIX Mode"The shell is intended to be POSIX compliant, however, in some cases, POSIXbehaviour is contrary either to the original Korn shell behaviour or touser convenience.How the shell behaves in these cases is determined by the state ofthe posix option (\fBset \-o posix\fP) \(em if it is on, the POSIX behaviouris followed, otherwise it is not.The \fBposix\fP option is set automatically when the shell starts upif the environment contains the \fBPOSIXLY_CORRECT\fP parameter.(The shell can also be compiled so that it is in POSIX mode by default,however this is usually not desirable)..PPThe following is a list of things that are affected by the state ofthe \fBposix\fP option:.nr P2 \n(PD.nr PD 0.sh(.IP \ \ \(bureading of \fB$ENV\fP: if not in posix mode, the \fBENV\fP parameteris not expanded and included when the shell starts..sh).IP \ \ \(bu\fB\e"\fP inside double quoted \fB`\fP..\fB`\fP command substitutions:in posix mode, the \fB\e"\fP is interpreted when the command is interpreted;in non-posix mode, the backslash is stripped before the command substitutionis interpreted.  For example, \fBecho "`echo \e"hi\e"`"\fP produces `"hi"' inposix mode, `hi' in non-posix mode.  To avoid problems, use the \fB$(...\fP)form of command substitution..IP \ \ \(bu\fBkill \-l\fP output: in posix mode, signal names are listed one a single line;in non-posix mode, signal numbers, names and descriptions are printed incolumns.In future, a new option (\fB\-v\fP perhaps) will be added to distinguishthe two behaviours..IP \ \ \(bu\fBfg\fP exit status: in posix mode, the exit status is 0 if no errors occur;in non-posix mode, the exit status is that of the last foregrounded job..IP \ \ \(bu\fBeval\fP exit status: if eval gets to see an empty command (\fIe.g.\fP,\fBeval "`false`"\fP), its exit status in posix mode will be 0.In non-posix mode, it will be the exit status of the lastcommand substitution that was done in the processing of the arguments to eval(or 0 if there were no command substitutions)..IP \ \ \(bu\fBgetopts\fP: in posix mode, options must start with a \fB\-\fP; in non-posixmode, options can start with either \fB\-\fP or \fB+\fP..IP \ \ \(bubrace expansion (also known as alternation): in posix mode, brace expansionis disabled; in non-posix mode, brace expansion enabled.Note that \fBset \-o posix\fP (or setting the \fBPOSIXLY_CORRECT\fP parameter)automatically turns the \fBbraceexpand\fP option off, however it can beexplicitly turned on later..IP \ \ \(bu\fBset \-\fP: in posix mode, this does not clear the \fBverbose\fP or\fBxtrace\fP options; in non-posix mode, it does..IP \ \ \(bu\fBset\fP exit status: in posix mode, the exit status of set is 0if there are no errors; in non-posix mode, the exit status is that ofany command substitutions performed in generating the set command.For example, `\fBset \-\- `false`; echo $?\fP' prints 0 in posix mode,1 in non-posix mode.  This construct is used in most shell scripts thatuse the old \fIgetopt\fP(1) command..IP \ \ \(buargument expansion of \fBalias\fP, \fBexport\fP, \fBreadonly\fP, and\fBtypeset\fP commands: in posix mode, normal argument expansion done;in non-posix mode, field splitting, file globing, brace expansion and(normal) tilde expansion are turned off, and assignment tilde expansionis turned on..IP \ \ \(busignal specification: in posix mode, signals can be specified as digits onlyif signal numbers match POSIX values (\fIi.e.\fP, HUP=1, INT=2, QUIT=3, ABRT=6,KILL=9, ALRM=14, and TERM=15); in non-posix mode, signals can be always digits..IP \ \ \(bualias expansion: in posix mode, alias expansion is only carried out whenreading command words; in non-posix mode, alias expansion is carried outon any word following an alias that ended in a space.For example, the following for loop.RS.ft Balias a='for ' i='j'.bra i in 1 2; do echo i=$i j=$j; done.ft P.REuses parameter \fBi\fP in posix mode, \fBj\fP in non-posix mode..IP \ \ \(butest: in posix mode, the expression "\fB-t\fP" (preceded bysome number of "\fB!\fP" arguments) is always true as it is a non-zero lengthstring; in non-posix mode, it tests if file de

⌨️ 快捷键说明

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