sh.1
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 1 代码 · 共 906 行 · 第 1/2 页
1
906 行
.\" SCCSID: @(#)sh.1 8.3 11/26/90.TH sh 1 .SH Namesh, for, case, if, while, :, ., break, continue, cd, eval, exec, exit, export, login, read, readonly, set, shift, times, trap, umask, wait \- command language.SH Syntax.B sh[.B \-ceiknrstuvx] [.I arg...] .SH Description.NX R "sh command interpreter"The.PN shcommand is a command programming language that executes commands readfrom a terminal or a file. See.B Invocationfor the meaning of arguments to the shell..PP.B Commands.brA.I simple commandis a sequence of nonblank.I wordsseparated by blanks (a blank is a.B tabor a.BR space )..NX R "simple command" "defined"The first word specifies the name of the command to be executed.Except as specified below, the remaining words are passed as argumentsto the invoked command. The command name is passed as argument 0. Forfurther information, see.MS execve 2 .The.I valueof a simple command is its exit status if it terminates normally or.RI 200+ statusif it terminates abnormally. For a list of status values, see .MS sigvec 2 ..PPA.I pipelineis a sequence of one or more.I commandsseparated by.BR \(or ..NX R "pipeline" "defined"The standard output of each command but the last is connected by a.MS pipe 2to the standard input of the next command. Each command is run as aseparate process; the shell waits for the last command to terminate..PPA.I listis a sequence of one or more.I pipelinesseparated by.BR ; ,.BR & ,.B &&or.B \(or\|\(orand optionally terminated by.B ;or.BR & . .NX R "pipeline" "lists".B ;and.B &have equal precedence which is lower than that of.B &&and.BR \(or\|\(or ,.B &&and.B \(or\|\(oralso have equal precedence. A semicolon causes sequential execution.An ampersand causes the preceding.I pipelineto be executed without waiting for it to finish. The symbol.B &&.RB ( \(or\|\(or )causes the.I listfollowing to be executed only if the preceding.I pipelinereturns a zero (nonzero) value. Newlines may appear in a.I list,instead of semicolons, to delimit commands..PPA.I commandis either a simple command or one of the following. The value returnedby a command is that of the last simple command executed in thecommand..IP "\fBfor \fIname \fR[ \fBin \fIword \&...\fR ] \fBdo \fIlist \fBdone".NX R "for command (sh)"Each time a.B forcommand is executed, .I nameis set to the next word in the.B forword list. If.B in.I word\&...is omitted,.B in"$@"is assumed. Execution ends when there are no more words in the list..IP "\fBcase \fIword \fBin \fR[ \fIpattern \fR[ | \fIpattern \fR] \&...) \fIlist \fR;; ] ... \fBesac".NX R "case command (sh)"A.B casecommand executes the.I listassociated with the first pattern that matches.I word.The form of the patterns is the same as that used for file namegeneration..IP "\fBif \fIlist \fBthen \fIlist \fR[ \fBelif \fIlist \fBthen \fIlist \fR] ... [ \fBelse \fIlist \fR] \fBfi".NX R "if command (sh)"The.I listfollowing.B ifis executed and if it returns zero, the.I listfollowing.B thenis executed. Otherwise, the.I listfollowing.B elifis executed and if its value is zero, the.I listfollowing.B thenis executed. Failing that, the.B else.I listis executed..IP "\fBwhile \fIlist \fR[ \fBdo \fIlist \fR] \fBdone".NX R "while command (sh)"A.B whilecommand repeatedly executes the.B while.I listand, if its value is zero, executes the.B do.I list;otherwise the loop terminates. The value returned by a.B whilecommand is that of the last executed command in the.B do.I list.\ Use.B untilin place of.B whileto negate the loop termination test..TP.BI ( " list " )Execute.I listin a subshell..TP.BI { " list " }.I listis simply executed..PPThe following words are only recognized as the first word of a commandand when not quoted..IP.Bif then else elif fi case in esac for while until do done { }.PP.B Command substitution.br.NX R "sh command interpreter" "command substitution"The standard output from a command enclosed in a pair of back quotes .RB ( \`\|\` )may be used as part or all of a word; trailing new lines are removed..PP.B Parameter substitution.br.NX R "sh command interpreter" "parameter substitution"The character.B $is used to introduce substitutable parameters. Positional parametersmay be assigned values by.BR set .Variables may be set by writing.IP.IB name = value[\ .IB name = value\ ] ....TP$\fB\|{\fIparameter\fB\|}\fRA.I parameteris a sequence of letters, digits or underscores (a.IR name ),a digit, or any of the characters.B* @ # ? \- $ !\|. .NX R "parameter" "defined"The value, if any, of the parameter is substituted. The braces arerequired only when.I parameteris followed by a letter, digit, or underscore that is not to beinterpreted as part of its name. If.I parameteris a digit, it is a positional parameter. If.I parameteris.BR * " or" " @"then all the positional parameters, starting with.BR $1 ,are substituted separated by spaces..B $0is set from argument zero when the shell is invoked..TP$\fB\|{\fIparameter\|\-word\|\fB}\fRIf.I parameteris set, substitute its value; otherwise substitute.I word..TP$\fB\|{\fIparameter\|\(eq\|word\|\fB}\fRIf.I parameteris not set, set it to.I word;the value of the parameter is then substituted. Positional parametersmay not be assigned to in this way..TP$\fB\|{\fIparameter\|?\|word\|\fB}\fRIf.I parameteris set, substitute its value; otherwise, print.I wordand exit from the shell. If.I wordis omitted, a standard message is printed..TP$\fB\|{\fIparameter\|\(plword\|\fB}\fRIf.I parameteris set, substitute.I word;otherwise substitute nothing..PPIn the above.I wordis not evaluated unless it is to be used as the substituted string.(So that, for example, echo ${d\-\`pwd\`} will only execute.I pwdif.I dis unset.).PPThe following.I parametersare automatically set by the shell..RS.TP.B #The number of positional parameters in decimal..PD 0.TP.B \-Options supplied to the shell on invocation or by.BR set ..TP.B ?The value returned by the last executed command in decimal..TP.B $The process number of this shell..TP.B !The process number of the last background command invoked..PD.RE.PPThe following.I parametersare used but not set by the shell..RS.TP.BHOMEThe default argument (home directory) for the.B cdcommand..PD 0.TP.BPATHThe search path for commands (see.BR execution )..TP.BMAILIf this variable is set to the name ofa mail file, the shell informs the user ofthe arrival of mail in the specified file..TP.B PS1Primary prompt string, by default `$ '..TP.B PS2Secondary prompt string, by default `> '..TP.B IFSInternal field separators, normally.BR space ,.BR tab ,and.BR new line ..PD.RE.PP.B Blank interpretation.brAfter parameter and command substitution,any results of substitution are scanned for internal field separatorcharacters (those found in.BR $IFS \*S)and split into distinct arguments where such characters are found.Explicit null arguments ("" or \'\') are retained.Implicit null arguments (those resulting from.I parametersthat have no values) are removed..PP.B File name generation.brFollowing substitution, each command word is scanned for the characters.BR * ,.B ?and.B [\ .If one of these characters appears, the word is regarded as a pattern..NX R "pattern" "matching"The word is replaced with alphabetically sorted file names that match thepattern. If no file name is found that matches the pattern,the word is left unchanged. The character.B .at the start of a file name or immediately following a.BR / ,and the character.BR / ,must be matched explicitly..TP .B *Matches any string, including the null string..PD 0.TP .B ?Matches any single character..TP .B [\ ...\ ]Matches any one of the characters enclosed.A pair of characters separated by.B \-matches any character lexically between the pair..PD.PP.B Quoting..br.NX R "sh command interpreter" "quoting characters"The following characters have a special meaning to the shelland cause termination of a word unless quoted..IP.B; & ( ) \(or < > new line space tab.PPA character may be.I quotedby preceding it with a.B\e\|. \enew-lineis ignored. All characters enclosed between a pair of quote marks.RB ( \'\|\' ),except a single quote, are quoted. Inside double quotes.RB ( "\|" )parameter and command substitution occurs and.B\equotes the characters.B\e \' "and.BR $ \|..PP.B"$*"is equivalent to.B"$1 $2 ..."whereas.br.B"$@"is equivalent to.B"$1" "$2" ... ..PP.B Prompting.br.NX R "sh command interpreter" "prompts"When used interactively, the shell prompts with the value ofPS1before reading a command.If at any time a new line is typed and further input is neededto complete a command, the secondary prompt.RB ( \s-2$PS2\s0 )is issued..PP.B Input output.br.NX R "sh command interpreter" "directing input".NX R "sh command interpreter" "directing output"Before a command is executed, its input and output may be redirectedusing a special notation interpreted by the shell. The following mayappear anywhere in a simple command or may precede or follow a.I commandand are not passed on to the invoked command. Substitution occursbefore.I wordor.I digitis used..IP <\fI\|wordUse file.I wordas standard input (file descriptor 0)..PD.IP >\fI\|wordUse file.I wordas standard output (file descriptor 1). If the file does not exist, itis created; otherwise it is truncated to zero length..IP >>\fI\|word
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?