📄 sh.1
字号:
When used interactively,the shell prompts with the value of.SMPS1before reading a command.If at any time a newline is typed and further input is neededto complete a command then the secondary prompt.RB ( \s-2$PS2\s0 )is issued..PP.B Input output..brBefore a command is executed its input and outputmay be redirected using a special notation interpreted by the shell.The following may appear anywhere in a simple-commandor may precede or follow a.I commandand are not passed on to the invoked command.Substitution occurs before.I wordor.I digitis used..TP\*(LT\fI\|word\fPUse file.I wordas standard input (file descriptor 0)..PD.TP\*(GT\fI\|word\fPUse file.I wordas standard output (file descriptor 1).If the file does not exist then it is created;otherwise it is truncated to zero length..TP\*(GT\*(GT\fI\|word\fPUse file.I wordas standard output.If the file exists then output is appended (by seeking to the end);otherwise the file is created..TP\*(LT\*(LT\fI\|word\fPThe shell input is read up to a line the same as.IR word ,or end of file.The resulting document becomesthe standard input.If any character of.I wordis quoted then no interpretationis placed upon the characters of the document;otherwise, parameter and command substitution occurs,.B\\newlineis ignored,and.B\\is used to quote the characters.B\\ $ \`and the first character of.I word..TP\*(LT\|&\|\fIdigit\fPThe standard input is duplicated from file descriptor.I digit;see.IR dup (2).Similarly for the standard output using \*(GT\|..TP\*(LT\|&\|\-The standard input is closed.Similarly for the standard output using \*(GT\|..PD.LPIf one of the above is preceded by a digitthen thefile descriptor created is that specifiedby the digit(instead of the default 0 or 1).For example,.LP \&... 2\*(GT&1.LPcreates file descriptor 2 to be a duplicateof file descriptor 1..LPIf a command is followed by.B &then the default standard inputfor the commandis the empty file(/dev/null).Otherwise, the environment for the execution of a command contains thefile descriptors of the invoking shell as modified by inputoutput specifications..PP.B Environment..brThe environmentis a list of name-value pairs that is passed toan executed program in the same way as a normal argument list;see.IR exec (2)and.IR environ (5).The shell interacts with the environment in several ways.On invocation, the shell scans the environmentand creates a.I parameterfor each name found,giving it the corresponding value.Executed commands inherit the same environment.If the user modifies the values of these.I parametersor creates new ones,none of these affects the environmentunless the.B exportcommand is used to bind the shell's.I parameterto the environment.The environment seen by any executed command is thus composedof any unmodified name-value pairs originally inherited by the shell,plus any modifications or additions,all of which must be noted in.B exportcommands..LPThe environment for any.I simple-commandmay be augmented by prefixing it with one or more assignments to.I parameters.Thus these two lines are equivalent.IPTERM=450 cmd args.br(export TERM; TERM=450; cmd args).LPIf the.B \-kflag is set,.I allkeyword arguments are placed in the environment,even if the occur after the command name.The following prints `a=b c' and `c':.nfecho a=b cset \-kecho a=b c.fi.PP.B Signals..brThe INTERRUPT and QUIT signals for an invokedcommand are ignored if the command is followed by.BR & ;otherwise signals have the valuesinherited by the shell from its parent.(But see also.BR trap. ).PP.B Execution..brEach time a command is executed the above substitutionsare carried out.Except for the `special commands' listed below a newprocess is created andan attempt is made to execute the command via an.IR exec (2)..LPThe shell parameter.B.SM $PATHdefines the search path forthe directory containing the command.Each alternative directory name is separated bya colon.RB ( : ).The default path is.BR :/bin:/usr/bin .If the command name contains a / then the search pathis not used.Otherwise, each directory in the path issearched for an executable file.If the file has execute permission but is not an.I a.outfile,it is assumed to be a file containing shell commands.A subshell (i.e., a separate process) is spawned to read it.A parenthesized command is also executed ina subshell..PP.B Special commands..brThe following commands are executed in the shell processand except where specifiedno input output redirection is permitted for such commands..TP.B :No effect; the command does nothing..PD 0.TP.BI . \ fileRead and execute commands from.I fileand return.The search path.B.SM $PATHis used to find the directory containing.IR file ..TP\fBbreak\fR \*(OK\fIn\fR\*(CKExit from the enclosing.B foror.B whileloop, if any.If.I nis specified then break.I nlevels..TP\fBcontinue\fR \*(OK\fIn\fR\*(CKResume the next iteration of the enclosing.B foror.B whileloop.If.I nis specified then resume at the.IR n -thenclosing loop..TP\fBcd\fR \*(OK\fIarg\fR\*(CKChange the current directory to.I arg.The shellparameter.B.SM $HOMEis the default.IR arg ..TP\fBeval\fR \*(OK\fIarg \fR...\*(CKThe arguments are read as inputto the shelland the resulting command(s) executed..TP\fBexec\fR \*(OK\fIarg \fR...\*(CKThe command specified bythe arguments is executed in place of this shellwithout creating a new process.Input output arguments may appear and if no otherarguments are given cause the shell inputoutput to be modified..TP\fBexit\fR \*(OK\fIn\fR\*(CKCauses a non interactive shell to exitwith the exit status specified by.I n.If.I nis omitted then the exit status is that of the last command executed.(An end of file will also exit from the shell.).TP\fBexport\fR \*(OK\fIname\fR ...\*(CKThe given names are markedfor automatic export to the.I environmentof subsequently-executed commands.If no arguments are given then a list ofexportable names is printed..TP\fBlogin\fR \*(OK\fIarg\fR ...\*(CKEquivalent to `exec login arg ...'..TP\fBnewgrp\fR \*(OK\fIarg \fR...\*(CKEquivalent to `exec newgrp arg ...'..TP.BI read \ name\ ...One line is read from the standard input;successive words of the input are assigned to thevariables.I namein order,with leftover words to the last variable.The return code is 0 unless the end-of-file is encountered..TP\fBreadonly\fR \*(OK\fIname \fR...\*(CKThe given names are marked readonly andthe values of the these names may not be changedby subsequent assignment.If no arguments are given then a listof all readonly names is printed..TP\fBset\fR \*(OK\fB\-eknptuvx\fR \*(OK\fIarg \fR...\*(CK\*(CK.RS.PD 0.TP 3m.B \-eIf non interactive then exit immediately if a command fails..TP.B \-kAll keyword arguments are placed in the environment for a command,not just those that precede the command name..TP.B \-nRead commands but do not execute them..TP.B \-tExit after reading and executing one command..TP.B \-uTreat unset variables as an error when substituting..TP.B \-vPrint shell input lines as they are read..TP.B \-xPrint commands and their arguments as they are executed..TP.B \-Turn off the.B \-xand.B \-voptions..PD.LPThese flags can also be used upon invocation of the shell.The current set of flags may be found in.BR $\- ..LPRemaining arguments are positionalparameters and are assigned, in order, to.SM.BR $1 ,.SM.BR $2 ,etc.If no arguments are given then the valuesof all names are printed..RE.TP.B shiftThe positional parameters from.SM.BR $2 ...are renamed.SM.BR $1 ....TP.B timesPrint the accumulated user and system times forprocesses run from the shell..TP\fBtrap\fR \*(OK\fIarg\fR\*(CK \*(OK\fIn\fR\*(CK ....I Argis a command to be read and executed when the shellreceives signal(s).I n.(Note that.I argis scanned once whenthe trap is set and once when the trapis taken.)Trap commands are executed in order of signal number.If.I argis absent then all trap(s).I nare resetto their original values.If.I argis the nullstring then this signal is ignored by the shell and by invoked commands.If.I nis 0 then the command.I argis executedon exit from the shell,otherwise upon receipt of signal.I nas numbered in.IR signal (2)..I Trapwith no arguments prints a listof commands associated with each signal number..TP\fBumask \fR[ \fInnn\fR ]The user file creation mask is set tothe octal value.I nnn(see.IR umask (2)).If.I nnnis omitted, the current value of the mask is printed..TP\fBwait\fP \*(OK\fIn\fP\*(CKWait for the specified process andreport its termination status.If.I nis not given then all currently active child processes are waited for.The return code from this command is that ofthe process waited for..PD.LP.PP.B Invocation..brIf the first character of argument zero is.BR \- ,commands are read from.BR \s-2$HOME\s0/.\|profile ,if such a file exists.Commands are then read as described below.The following flags are interpreted by the shellwhen it is invoked..PD 0.TP 11n.BI \-c \ stringIf the.B \-cflag is present thencommands are read from.I string\|..TP 11n.B \-sIf the.B \-sflag is present or if noarguments remainthen commands are read from the standard input.Shell output is written tofile descriptor 2..TP 11n.B \-iIf the.B \-iflag is present orif the shell input and output are attached to a terminal (as told by.IR gtty )then this shell is.I interactive.In this case the terminate signalSIGTERM (see.IR signal (2))is ignored (so that `kill 0'does not kill an interactive shell) and the interrupt signalSIGINT is caught and ignored(so that.B waitis interruptable).In all cases SIGQUIT is ignored by the shell..PD.LPThe remaining flags and arguments are described under the.B setcommand..SH FILES.RB $HOME/ . \^profile.br/tmp/sh*.br/dev/null.SH SEE ALSOtest(1),exec(2),.SH DIAGNOSTICSErrors detected by the shell, such as syntax errorscause the shellto return a non zero exit status.If the shell is being used non interactivelythen execution of the shell file is abandoned.Otherwise, the shell returns the exit status ofthe last command executed (see also.BR exit )..SH BUGSIf \*(LT\*(LT is used to provide standard input to an asynchronousprocess invoked by &,the shell gets mixed up about naming the input document.A garbage file /tmp/sh* is created, and the shell complains aboutnot being able to find the file by another name.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -