📄 ksh.man
字号:
'\" t.\"{{{}}}.\"{{{ Notes about man page.\" - use the pseudo-macros .sh( and .sh) to begin and end sh-specific.\" text and .ksh( and .ksh) for ksh specific text..\" - put i.e., e.g. and etc. in italics.\"}}}.\"{{{ To do.\" todo: Things not covered that should be:.\" - distinguish (POSIX) special built-in's, (POSIX) regular built-in's,.\" and sh/ksh weirdo built-in's (put S,R,X superscripts after command.\" name in built-in commands section?).\" - need to be consistent about notation for `See section-name', `.\" See description of foobar command', `See section section-name', etc..\" - need to use the term `external command' meaning `a command that is .\" executed using execve(2)' (as opposed to a built-in command or .\" function) for more clear description..\"}}}.\"{{{ Title.ksh(.TH KSH 1 "August 19, 1996" "" "User commands".ksh).sh(.TH SH 1 "August 19, 1996" "" "User commands".sh).\"}}}.\"{{{ Name.SH NAME.ksh(ksh \- Public domain Korn shell.ksh).sh(sh \- Public domain Bourne shell.sh).\"}}}.\"{{{ Synopsis.SH SYNOPSIS.ad l.ksh(\fBksh\fP.ksh).sh(\fBsh\fP.sh)[\fB\(+-abCefhikmnprsuvxX\fP] [\fB\(+-o\fP \fIoption\fP] [ [ \fB\-c\fP \fIcommand-string\fP [\fIcommand-name\fP] | \fB\-s\fP | \fIfile\fP ] [\fIargument\fP ...] ].ad b.\"}}}.\"{{{ Description.SH DESCRIPTION.ksh(\fBksh\fP is a command interpreter that is intended for both interactive and shell script use. Its command language is a supersetof the \fIsh\fP(1) shell language..ksh).sh(\fBsh\fP is a reimplementation of the Bourne shell, a commandinterpreter for both interactive and script use..sh).\"{{{ Shell Startup.SS "Shell Startup"The following options can be specified only on the command line:.IP "\fB\-c\fP \fIcommand-string\fP"the shell executes the command(s) contained in \fIcommand-string\fP.IP \fB\-i\fPinteractive mode \(em see below.IP \fB\-l\fPlogin shell \(em see belowinteractive mode \(em see below.IP \fB\-s\fPthe shell reads commands from standard input; all non-option argumentsare positional parameters.IP \fB\-r\fPrestricted mode \(em see below.PPIn addition to the above, the options described in the \fBset\fP built-incommand can also be used on the command line..PPIf neither the \fB\-c\fP nor the \fB\-s\fP options are specified, thefirst non-option argument specifies the name of a file the shell readscommands from; if there are no non-option arguments, the shell readscommands from standard input.The name of the shell (\fIi.e.\fP, the contents of the \fB$0\fP) parameteris determined as follows: if the \fB\-c\fP option is used and there isa non-option argument, it is used as the name; if commands are beingread from a file, the file is used as the name; otherwise the namethe shell was called with (\fIi.e.\fP, argv[0]) is used..PPA shell is \fBinteractive\fP if the \fB\-i\fP option is used orif both standard input and standard error are attached to a tty.An interactive shell has job control enabled (if available),ignores the INT, QUIT and TERM signals, and prints prompts beforereading input (see \fBPS1\fP and \fBPS2\fP parameters).For non-interactive shells, the \fBtrackall\fP option is on by default(see \fBset\fP command below)..PPA shell is \fBrestricted\fP if the \fB\-r\fP option is used or if eitherthe basename of the name the shell is invoked with or the \fBSHELL\fPparameter match the pattern *r*sh (\fIe.g.\fP, rsh, rksh, rpdksh, \fIetc.\fP).The following restrictions come into effect after the shell processesany profile and \fB$ENV\fP files:.nr P2 \n(PD.nr PD 0.IP \ \ \(buthe \fBcd\fP command is disabled.IP \ \ \(buthe \fBSHELL\fP, \fBENV\fP and \fBPATH\fP parameters can't be changed.IP \ \ \(bucommand names can't be specified with absolute or relative paths.IP \ \ \(buthe \fB\-p\fP option of the \fBcommand\fP built-in can't be used.IP \ \ \(buredirections that create files can't be used (\fIi.e.\fP, \fB>\fP,\fB>|\fP, \fB>>\fP, \fB<>\fP).nr PD \n(P2.PPA shell is \fBprivileged\fP if the \fB\-p\fP option is used or ifthe real user-id or group-id does not match the effective user-idor group-id (see \fIgetuid\fP(2), \fIgetgid\fP(2)).A privileged shell does not process $HOME/.profile nor the \fBENV\fPparameter (see below), instead the file /etc/suid_profile is processed.Clearing the privileged option causes the shell to set its effectiveuser-id (group-id) to its real user-id (group-id)..PPIf the basename of the name the shell is called with (\fIi.e.\fP, argv[0])starts with \fB\-\fP or if the \fB\-l\fP option is used, the shell is assumedto be a login shell and the shell reads and executes the contents of\fB/etc/profile\fP and \fB$HOME/.profile\fP if they exist and are readable..PPIf the \fBENV\fP parameter is set when the shell starts (or, in thecase of login shells, after any profiles are processed), its valueis subjected to parameter, command, arithmetic and tilde substitution andthe resulting file (if any) is read and executed.If \fBENV\fP parameter is not set (and not null) and pdksh was compiledwith the \fBDEFAULT_ENV\fP macro defined, the file named in that macrois included (after the above mentioned substitutions have been performed)..PPThe exit status of the shell is 127 if the command file specifiedon the command line could not be opened, or non-zero if a fatal syntaxerror occurred during the execution of a script.In the absence of fatal errors, the exit status is that of the lastcommand executed, or zero, if no command is executed..\"}}}.\"{{{ Command Syntax.SS "Command Syntax".\"{{{ words and tokensThe shell begins parsing its input by breaking it into \fIword\fPs.Words, which are sequences of characters, are delimited by unquoted\fIwhite-space\fP characters (space, tab and newline) or \fImeta-characters\fP(\fB<\fP, \fB>\fP, \fB|\fP, \fB;\fP, \fB&\fP, \fB(\fP and \fB)\fP).Aside from delimiting words, spaces and tabs are ignored, whilenewlines usually delimit commands.The meta-characters are used in building the following tokens:\fB<\fP, \fB<&\fP, \fB<<\fP, \fB>\fP, \fB>&\fP, \fB>>\fP, \fIetc.\fP areused to specify redirections (see Input/Output Redirection below);\fB|\fP is used to create pipelines;.ksh(\fB|&\fP is used to create co-processes (see Co-Processes below);.ksh)\fB;\fP is used to separate commands;\fB&\fP is used to create asynchronous pipelines;\fB&&\fP and \fB||\fP are used to specify conditional execution;\fB;;\fP is used in \fBcase\fP statements;.ksh(\fB((\fP .. \fB))\fP are used in arithmetic expressions;.ksh)and lastly,\fB(\fP .. \fB)\fP are used to create subshells..PPWhite-space and meta-characters can be quoted individually usingbackslash (\fB\e\fP), or in groups using double (\fB"\fP) or single (\fB'\fP)quotes.Note that the following characters are also treated specially by the shell andmust be quoted if they are to represent themselves:\fB\e\fP, \fB"\fP, \fB'\fP, \fB#\fP, \fB$\fP, \fB`\fP, \fB~\fP, \fB{\fP,\fB}\fP, \fB*\fP, \fB?\fP and \fB[\fP.The first three of these are the above mentioned quoting characters(see Quoting below);\fB#\fP, if used at the beginning of a word, introduces a comment \(em everythingafter the \fB#\fP up to the nearest newline is ignored;\fB$\fP is used to introduce parameter, command and arithmetic substitutions(see Substitution below);\fB`\fP introduces an old-style command substitution(see Substitution below);\fB~\fP begins a directory expansion (see Tilde Expansion below);\fB{\fP and \fB}\fP delimit \fIcsh\fP(1) style alternations(see Brace Expansion below);and, finally, \fB*\fP, \fB?\fP and \fB[\fP are used in file name generation(see File Name Patterns below)..\"}}}.\"{{{ simple-command.PPAs words and tokens are parsed, the shell builds commands, of whichthere are two basic types: \fIsimple-commands\fP, typically programsthat are executed, and \fIcompound-commands\fP, such as \fBfor\fP and\fBif\fP statements, grouping constructs and function definitions..PPA simple-command consists of some combination of parameter assignments (seeParameters below), input/output redirections (see Input/Output Redirectionsbelow), and command words; the only restriction is that parameter assignmentscome before any command words.The command words, if any, define the command that is to be executed and itsarguments.The command may be a shell built-in command, a function or an \fIexternalcommand\fP, \fIi.e.\fP, a separate executable file that is located using the\fBPATH\fP parameter (see Command Execution below).Note that all command constructs have an \fIexit status\fP: for externalcommands, this is related to the status returned by \fIwait\fP(2) (if thecommand could not be found, the exit status is 127, if it could not beexecuted, the exit status is 126);the exit status of other command constructs (built-in commands, functions,compound-commands, pipelines, lists, \fIetc.\fP) are all well defined and aredescribed where the construct is described.The exit status of a command consisting only of parameter assignments is thatof the last command substitution performed during the parameter assignmentor zero if there were no command substitutions..\"}}}.\"{{{ pipeline.PPCommands can be chained together using the \fB|\fP token toform \fIpipelines\fP, in which the standard output of each command butthe last is piped (see \fIpipe\fP(2)) to the standard input of the followingcommand.The exit status of a pipeline is that of its last command.A pipeline may be prefixed by the \fB!\fP reserved word whichcauses the exit status of the pipeline to be logicallycomplemented: if the original status was 0 the complemented status willbe 1, and if the original status was not 0, then the complementedstatus will be 0..\"}}}.\"{{{ lists.PP\fILists\fP of commands can be created by separating pipelines byany of the following tokens: \fB&&\fP, \fB||\fP, \fB&\fP, \fB|&\fP and \fB;\fP.The first two are for conditional execution: \fIcmd1\fP \fB&&\fP \fIcmd2\fPexecutes \fIcmd2\fP only if the exit status of \fIcmd1\fP is zero;\fB||\fP is the opposite \(em \fIcmd2\fP is executed only if the exit statusof \fIcmd1\fP is non-zero.\fB&&\fP and \fB||\fP have equal precedence which is higher than that of\fB&\fP, \fB|&\fP and \fB;\fP, which also have equal precedence.The \fB&\fP token causes the preceding command to be executed asynchronously,that is, the shell starts the command, but does not wait for it to complete(the shell does keep track of the status of asynchronous commands \(em seeJob Control below).When an asynchronous command is started when job control is disabled(\fIi.e.\fP, in most scripts), the command is started with signals INTand QUIT ignored and with input redirected from /dev/null(however, redirections specified in the asynchronous command have precedence)..ksh(The \fB|&\fP operator starts a \fIco-process\fP which is special kind ofasynchronous process (see Co-Processes below)..ksh)Note that a command must follow the \fB&&\fP and \fB||\fP operators, whilea command need not follow \fB&\fP, \fB|&\fP and \fB;\fP.The exit status of a list is that of the last command executed, with theexception of asynchronous lists, for which the exit status is 0..\"}}}.\"{{{ compound-commands.PPCompound commands are created using the following reserved words \(em thesewords are only recognized if they are unquoted and if they are used asthe first word of a command (\fIi.e.\fP, they can't be preceded by parameterassignments or redirections):.TScenter;lfB lfB lfB lfB lfB .case else function then !do esac if time [[done fi in until {elif for select while }.TE\fBNote:\fP Some shells (but not this one) execute control structure commandsin a subshell when one or more of their file descriptors are redirected, soany environment changes inside them may fail.To be portable, the \fBexec\fP statement should be used instead to redirectfile descriptors before the control structure..PPIn the following compound command descriptions, command lists (denoted as\fIlist\fP) that are followed by reserved words must end with asemi-colon, a newline or a (syntactically correct) reserved word.For example,.RS\fB{ echo foo; echo bar; }\fP.br\fB{ echo foo; echo bar<newline>}\fP.br\fB{ { echo foo; echo bar; } }\fP.REare all valid, but.RS\fB{ echo foo; echo bar }\fP.REis not..\"{{{ ( list ).IP "\fB(\fP \fIlist\fP \fB)\fP"Execute \fIlist\fP in a subshell. There is no implicit way to passenvironment changes from a subshell back to its parent..\"}}}.\"{{{ { list }.IP "\fB{\fP \fIlist\fP \fB}\fP"Compound construct; \fIlist\fP is executed, but not in a subshell.Note that \fB{\fP and \fB}\fP are reserved words, not meta-characters..\"}}}.\"{{{ case word in [ [ ( ] pattern [ | pattern ] ... ) list ;; ] ... esac.IP "\fBcase\fP \fIword\fP \fBin\fP [ [\fB(\fP] \fIpattern\fP [\fB|\fP \fIpattern\fP] ... \fB)\fP \fIlist\fP \fB;;\fP ] ... \fBesac\fP"The \fBcase\fP statement attempts to match \fIword\fP against the specified\fIpattern\fPs; the \fIlist\fP associated with the first successfully matchedpattern is executed. Patterns used in \fBcase\fP statements are the same asthose used for file name patterns except that the restrictions regarding\fB\&.\fP and \fB/\fP are dropped. Note that any unquoted space before andafter a pattern is stripped; any space with a pattern must be quoted. Both theword and the patterns are subject to parameter, command, and arithmeticsubstitution as well as tilde substitution.For historical reasons, open and close braces may be used instead
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -