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

📄 ksh.1

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 1
📖 第 1 页 / 共 5 页
字号:
.\".ds OK [\|.ds CK \|].\".de P.TH ksh 1.SH Nameksh, rksh \- KornShell, astandard/restricted command and programming language.SH Syntax.B ksh[.B \(+-aefhikmnoprstuvx] [.B \(+-ooption ] .\|.\|.[.B \-cstring ][ arg .\|.\|. ].br.B rksh[.B \(+-aefhikmnoprstuvx] [.B \(+-ooption ] .\|.\|.[.B \-cstring ][ arg .\|.\|. ].SH DescriptionThe .PN kshshell is a command and programming languagethat executes commands read from a terminalor a file.The rkshshell is a restricted version of the command interpreter.IR ksh ;it is used to set up login names and execution environments whosecapabilities are more controlled than those of the standard shell.See.B Invocationfor the meaning of arguments to the shell..SS DefinitionsA metacharacter is one of the following characters:.RS.PP\fB;   &   (   )   \(bv   <   >   new-line   space   tab\fP.RE.PPA blank is a.B tabor a.BR space .An identifieris a sequence of letters, digits, or underscoresstarting with a letter or underscore.Identifiers are used as names forfunctions and `named parameters'.A word is a sequence ofcharacters separated by one or more non-quotedmetacharacters..PPA commandis a sequence of characters in the syntaxof the shell language.The shell reads each command andcarries out the desired action either directly or by invokingseparate utilities.A special command is a command that is carried out by theshell without creating a separate process.Except for documentedside effects, most special commands can be implemented as separateutilities..SS CommandsA simple-command is a sequence of blankseparated wordswhich may be preceded by a parameter assignment list.See.B Environmentbelow.The first word specifies the name of the command tobe executed.Except as specified below,the remaining words are passed as argumentsto the invoked command.The command name is passed as argument 0(see.MS exec 2 ).The value of a simple-command is its exit statusif it terminates normally, or (octal) 200+\fIstatus\^\fP ifit terminates abnormally (see.MS signal 2for a list ofstatus values)..PPA pipelineis a sequence of one or morecommandsseparated by.BR \(bv .The standard output of each command but the lastis connected by a.MS pipe 2to the standard input of the next command.Each command is run as a separate process;the shell waits for the last command to terminate.The exit status of a pipeline is the exitstatus of the last command..PPA listis a sequence of one or morepipelinesseparated by.BR ; ,.BR & ,.BR && ,or.BR \(bv\|\(bv ,and optionally terminated by.BR ; ,.BR & ,or.BR \(bv& .Of these five symbols,.BR ; ,.BR & ,and.BR \(bv&have equal precedence,which is lower than that of.B &&and.BR \(bv\|\(bv .The symbols.B &&and.B \(bv\|\(bvalso have equal precedence.A semicolon.RB ( ; )causes sequential execution of the preceding pipeline; an ampersand.RB ( & )causes asynchronous execution of the preceding pipeline (that is, the shell doesnot wait for that pipeline to finish).  The symbol.B \(bv&causes asynchronous execution of the preceding command or pipelinewith a two-way pipe established to the parent shell.The standard input and output of the spawned commandcan be written to and read from by the parent Shellusing the.B \-poption of the special commands read and print described later.  The symbol.B &&.RB (\| \(bv\|\(bv )causes the list following it to be executed only if the preceding pipelinereturns a zero (non-zero) value.An arbitrary number of new-lines may appear in alist, instead of a semicolon,to delimit a command..PPA commandis either a simple-commandor one of the following.Unless otherwise stated,the value returned by a command is that of thelast simple-command executed in the command..TP\fBfor\fP \fIidentifier\^\fP \*(OK \fBin\fP \fIword\^\fP .\|.\|. \*(CK \fB;do\fP \fIlist\^\fP \fB;done\fPEach time a.B forcommand is executed, .I identifier is set to the next .I word taken from the.B in.I word list.If.B in .I word\&.\|.\|.is omitted, then the.B forcommand executes the \fBdo\fP \fIlist\^\fP once for each positional parameterthat is set(see.B "Parameter Substitution"\fR).Execution ends when there are no more words in the list..TP\fBselect\fP \fIidentifier\^\fP \*(OK \fBin\fP \fIword\^\fP .\|.\|. \*(CK \fB;do\fP \fIlist\^\fP \fB;done\fPA.B selectcommand prints on standard error (file descriptor 2), the set of.IR word s,each preceded by a number.If.BI in " word"\&.\|.\|.is omitted, then the positional parameters are used instead(see.B "Parameter Substitution"below).The PS3 prompt is printedand a line is read from the standard input.If this line consists of the numberof one of the listed.IR word s,then the value of the parameter.I identifieris set to the.I wordcorresponding to this number.If this line is empty the selection list isprinted again.Otherwise the value of the parameter.I identifieris set to null.  The contents of the line read from standard input issaved in the parameter REPLY.  The.I listis executed for each selection until abreak or end-of-file is encountered..TP\fBcase\fP \fIword\^\fP \fBin\fP \*(OK \*(OK\fB(\fP\*(CK\fIpattern\^\fP \*(OK \(bv \fIpattern\^\fP \*(CK .\|.\|. \fB)\fP \fIlist\^\fP \fB;;\fP \*(CK .\|.\|. \fBesac\fPA.B casecommand executes the.I listassociated with the first.I patternthat matches.IR word .The form of the patterns isthe same as that used forfile-name generation (see.B "File Name Generation"below)..TP\fBif\fP \fIlist\^\fP \fB;then\fP \fIlist\^\fP \*(OK \\fBelif\fP \fIlist\^\fP \fB;then\fP \fIlist\^\fP \*(CK .\|.\|. \\*(OK \fB;else\fP \fIlist\^\fP \*(CK \fB;f\&i\fPThe.I listfollowing \fBif\fP is executed and,if itreturns a zero exit status, the.I listfollowing the first.B thenis executed.  Otherwise, the.I listfollowing \fBelif\fPis executed and, if its value is zero, the.I listfollowing the next.B thenis executed.  Failing that, the.B else.I listis executed.  If no.B else.I listor.B then.I listis executed, then the.B ifcommand returns a zero exit status..TP.PD 0\fBwhile\fP \fIlist\^\fP \fB;do\fP \fIlist\^\fP \fB;done\fP.TP\fBuntil\fP \fIlist\^\fP \fB;do\fP \fIlist\^\fP \fB;done\fP.PDA.B whilecommand repeatedly executes the.B while.I listand, if the exit status of the last command in the list is zero, executesthe.B do.IR list ;otherwise the loop terminates.If no commands in the.B do.I listare executed, then the.B whilecommand returns a zero exit status;.B untilmay be used in place of.B whileto negatethe loop termination test..TP\fB(\fP\fIlist\^\fP\fB)\fPExecute.I listin a separate environment.Note, that if two adjacent open parentheses areneeded for nesting, a space must be inserted to avoidarithmetic evaluation as described below..TP\fB{ \fP\fIlist\^\fP\fB;}\fPThe .I listis simply executed.Note that unlike the metacharacters.B (and.BR ) ,.br.B {and.B }are `reserved words' and must at the beginning of a line or after a.B ;in order to be recognized..TP\fB[[\fP\fIexpression\^\fP\fB]]\fPEvaluates.I expressionand returns a zero exit status when.I expressionis true.See.B "Conditional Expressions"for a description of.IR expression..TP.PD 0\fBfunction\fP \fIidentifier\^\fP \fB{\fP \fIlist\^\fP \fB;}\fP.TP\fIidentifier\^\fP \fB() {\fP \fIlist\^\fP \fB;}\fP.PDDefine a function which is referenced by.IR identifier .The body of the function is the.I listof commands between.B {and.BR } .(See.B Functionsbelow)..TP\fBtime \fP\fIpipeline\^\fP.brThe.I pipelineis executed and the elapsed time as well asthe user and system time are printed on standard error..PPThe following reserved wordsare only recognized as the first word of a commandand when not quoted:.if t .RS.PP.B.if n if then else elif fi case esac for while until do done { } function select time [[ ]].if t if   then   else   elif   fi   case   esac   for   while   until   do   done   {   }   function   select   time  [[  ]].if t .RE.SS CommentsA word beginning with.B #causes that word and all the following characters up to a new-lineto be ignored..SS AliasingThe first word of each command is replaced by the text of analias if an alias for this word has been defined.  Thefirst character of an aliasname can be any non-special printable character,but the rest of the charactersmust be the same as for a valid identifier.The replacement string can contain anyvalid Shell scriptincluding the metacharacters listed above.The first word of each command in thereplaced text,other thanany that are in the process of being replaced,will be tested for aliases.If the last character of the alias value is a blankthen the word following the alias will also be checked for aliassubstitution.Aliases can be used to redefine specialbuiltin commands but cannot be used to redefinethe reserved words listed above.Aliases can be created, listed, and exported with the.PN aliascommand and can be removed with the.PN unaliascommand.Exported aliases remain in effect forscripts invoked by name,but must be reinitialized for separate invocationsof the Shell (See.B Invocationbelow)..PPAliasing is performed whenscripts are read,not while they are executed.Therefore,for an alias to take effectthe alias definition command has to be executed beforethe command which references the alias is read..PPAliases are frequently used as a short hand for full pathnames.An option to the aliasing facility allows the value of the aliasto be automatically set to the full pathname ofthe corresponding command.  These aliases are calledtracked aliases.  The value of a trackedalias is defined the first time the corresponding commandis looked up and becomes undefined each timethe PATH variable is reset.  These aliases remaintracked so that the nextsubsequent reference will redefine the value.Several tracked aliases are compiled into the shell.The.B \-hoption of the.PN setcommand makes each referenced command nameinto a tracked alias..PPThe following`exported aliases'are compiled into the shellbut can be unset or redefined:.RS 5.PD 0.TP.B "autoload=\(fmtypeset \-fu\(fm".TP.B "false=\(fmlet 0\(fm".TP.B "functions=\(fmtypeset \-f\(fm".TP.B "hash=\(fmalias \-t\(fm".TP.B "history=\(fmfc \-l\(fm".TP.B "integer=\(fmtypeset \-i\(fm".TP.B "nohup=\(fmnohup \(fm".TP.B "r=\(fmfc \-e \-\(fm".TP.B "true=\(fm:\(fm".TP.B "type=\(fmwhence \-v\(fm".PD.RE.SS Tilde SubstitutionAfter alias substitution is performed, each wordis checked to see if it begins with an unquoted.BR \(ap .If it does, then the word up to a.B /is checked to see if it matches a user name in the.PN /etc/passwdfile.If a match is found, the.B \(apand the matched login name is replaced by thelogin directory of the matched user.This is called a`tilde substitution'.If no match is found, the original text is left unchanged.A.B \(apby itself, or in front of a.BR / ,is replaced by the value of the HOME parameter.A.B \(apfollowed by a.B +or.B \-is replaced by $PWD and $OLDPWD respectively..PPIn addition, tilde substitution is attempted whenthe value of a `variable assignment parameter'begins with a.BR \(ap ..SS Command SubstitutionThe standard output from a command enclosed inparentheses preceded by a dollar sign (.B $(\|))or a pair of grave accents.Pn ( `` )may be used as part or allof a word;trailing new-lines are removed.In the second (archaic) form, the string between the quotes is processedfor special quoting characters before the command is executed. (See.BR Quoting ).The command substitution\^\fB$(\^cat file\^)\fP\^can be replaced by the equivalent but faster\^\fB$(\^<file\^)\fP\^.Command substitution of most special commandsthat do not perform input/output redirection arecarried out without creating a separate process..PPAn arithmetic expression enclosed in doubleparenthesis preceded by a dollar sign (.B $((\|)))is replaced by the value of the arithmetic expressionwithin the double parenthesis..SS Process Substitution.This feature is only available onversions of the operating system that support the.PN /dev/fddirectory for naming open files.Each command argument of the form\fB<(\fP\fIlist\^\fP\fB)\fPor\fB>(\fP\fIlist\^\fP\fB)\fPwill run process.I listasynchronously connected to some file in.PN /dev/fd .The name of this file will become the argument to the command.If the form with.B >is selected then writing on this file will provide input for.IR list .If.B <is used,then the file passed as an argument will contain the output of the.I listprocess.For example,.RS.PP\fBpaste <(cut \-f1\fP \fIfile1\fP\fB) <(cut \-f3\fP \fIfile2\fB) | tee >(\fP\fIprocess1\fP\fB) >(\fP\fIprocess2\fP\fB)\fP.RE.PP.BR cut sfields 1 and 3 fromthe files.I file1and.I file2respectively,.BR paste sthe results together, and sends it to the processes.I process1and.IR process2 ,as well as putting it onto the standard output.Note that the file, which is passed as an argument to the command,is a system.PN pipe so programs that expect to.PN lseekon the file will not work..SS Parameter SubstitutionA parameter is an identifier,one or more digits,or any of the characters.BR \(** ,.BR @ ,.BR # ,.BR ? ,.BR \- ,.BR $ ,and.BR !\\^ .A `named parameter' (a parameter denoted by an identifier)has a value and zero or more attributes.Named parameters can be assigned values and attributesby using the.PN typesetspecial command.The attributes supported by the Shell are describedlater with the.PN typesetspecial command.Exported parameters pass values and attributes tothe environment..PPThe shell supports a one-dimensional array facility.An element of an array parameter is referenced by asubscript.A subscript is denoted by a.BR [ ,followed by an`arithmetic expression'(see .B Arithmetic Evaluation)followed by a.BR ] .To assign values to an array, use\fBset \-A\fP \fIname\fP  \fIvalue\fP .\|.\|. .The value of allsubscripts must be in therange of

⌨️ 快捷键说明

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