sh.1

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 1 代码 · 共 906 行 · 第 1/2 页

1
906
字号
Use file.I wordas standard output.  If the file exists, output is appended (by seekingto the end); otherwise the file is created..IP <<\fI\|wordThe shell input is read up to a line the same as.IR word ,or end of file.  The resulting document becomes the standard input.  Ifany character of.I wordis quoted, no interpretation is placed upon the characters of thedocument; otherwise, parameter and command substitution occurs,.B\enew-lineis ignored, and.B\eis used to quote the characters.B\e $ \'and the first character of.I word..IP <\|&\fI\|digitThe standard input is duplicated from file descriptor.I digit;see.MS dup 2 .Similarly for the standard output using >\|..IP <\|&\|\-The standard input is closed.  Similarly for the standard output using>\|..PD.PPIf one of the above is preceded by a digit, the file descriptor createdis that specified by the digit (instead of the default 0 or 1).  Forexample,.PP	\&... 2>&1.PPcreates file descriptor 2 to be a duplicate of file descriptor 1..PPIf a command is followed by.B &then the default standard input for the command is the empty file.PN /dev/null .Otherwise, the environment for the execution of a command contains thefile descriptors of the invoking shell as modified by input outputspecifications..PP.B Environment.br.NX R "sh command interpreter" "environment"The environment is a list of name-value pairs that is passed to anexecuted program in the same way as a normal argument list; see.MS execve 2 and.MS environ 7 .The shell interacts with the environment in several ways.On invocation, the shell scans the environment and creates a.I parameterfor each valid name found (except IFS),giving it the corresponding value.(IFS cannot be set by the environment;it can only be set in the current shell session.)Executed commands inherit the same environment.If the user modifies the values of these.I parametersor creates new ones, none of these affects the environment unless 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..PPThe 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).PPIf the.B \-kflag is set,.I allkeyword arguments are placed in the environment,even if they 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.br.NX R "sh command interpreter" "signals"The INTERRUPT and QUIT signals for an invokedcommand are ignored if the command is followed by.BR & ;otherwise signals have the values inherited by the shell from its parent.(But see also.BR trap. ).PP.B Execution.br.NX R "sh command interpreter" "executing commands"Each time a command is executed, the above substitutions are carried out.Except for the special commands listed below, a new process is created andan attempt is made to execute the command with an.MS execve 2 ..PPThe shell parameter.B$PATHdefines the search path for the directory containing the command.Each alternative directory name is separated by a colon.RB ( : ).The default path is.BR :/bin:/usr/bin .If the command name contains a /, the search path is not used.Otherwise, each directory in the path is searched 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 (that is, a separate process) is spawned to read it.A parenthesized command is also executed in a subshell..PP.B Special commands.br.NX R "sh command interpreter" "special commands"The following commands are executed in the shell processand, except where specified, no 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$PATHis used to find the directory containing.IR file ..TP.B break.RI[\  n \ ].NX R "break command (sh)"Exit from the enclosing.B foror.B whileloop, if any.If.I nis specified, break.I nlevels..TP.B continue.RI[\  n \ ].NX R "continue command (sh)"Resume the next iteration of the enclosing.B foror.B whileloop.  If.I nis specified, resume at the.IR n thenclosing loop..TP\.B cd.RI[\  arg \ ].NX R "cd command (sh)"Change the current directory to.I arg.The shell parameter.B$HOMEis the default.IR arg ..TP.B eval.RI[\  arg ...\ ].NX R "eval command (sh)"The arguments are read as input to the shelland the resulting command(s) executed..TP.B exec.RI[\  arg ...\ ].NX R "exec command (sh)"The command specified by the arguments is executed in place of thisshell without creating a new process.  Input output arguments mayappear and if no other arguments are given cause the shell input outputto be modified..TP.B exit.RI[\  n \ ].NX R "exit command (sh)"Causes a noninteractive shell to exit with the exit status specified by.I n.If.I nis omitted, the exit status is that of the last command executed.  (Anend of file will also exit from the shell.).TP.B export.RI[\  name ...\ ].NX R "export command (sh)"The given names are marked for automatic export to the.I environmentof subsequently executed commands.  If no arguments are given, a listof exportable names is printed..TP.B login.RI[\  arg ...\ ].NX R "login command (sh)"Equivalent to 'exec login arg ...'..TP.B read.I name ....NX R "read command (sh)"One line is read from the standard input; successive words of the inputare assigned to the variables.I namein order, with leftover words to the last variable.  The return code is0 unless the end-of-file is encountered..TP.B readonly.RI[\  name ...\ ].NX R "readonly command (sh)"The given names are marked readonly and the values of these names maynot be changed by subsequent assignment.  If no arguments are given, alist of all readonly names is printed..TP.B set.RI[\  \-eknptuvx [\  arg ...\ ]\ ].NX R "set command (sh)".RS.PD 0.TP 3m.B \-eIf noninteractive, exit immediately if a command fails..TP.B \-kAll keyword arguments are placed in the environment for a command, notjust 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.PPThese flags can also be used upon invocation of the shell.  The currentset of flags may be found in.BR $\- ..PPRemaining arguments are positional parameters and are assigned, inorder, to.BR $1 ,.BR $2 ,and so forth.  If no arguments are given, the values of all names areprinted..RE.TP.B shift.NX R "shift command (sh)"The positional parameters from.BR $2 ...are renamed.BR $1 ....TP.B times.NX R "times command (sh)"Print the accumulated user and system times for processes run from theshell..TP.B trap.RI[\  arg \ ]\ [\  n \ ] ....NX R "trap command (sh)"The.I argis a command to be read and executed when the shell receives signal(s).I n.(Note that.I argis scanned once when the trap is set and once when the trap is taken.)Trap commands are executed in order of signal number.  If.I argis absent, all trap(s).I nare reset to their original values.If.I argis the null string, this signal is ignored by the shell and by invokedcommands.  If.I nis 0, the command.I argis executed on exit from the shell, otherwise upon receipt of signal.I nas numbered in.MS sigvec 2 .The.I trapwith no arguments prints a list of commands associated with each signalnumber..TP\fBumask \fR[\  \fInnn\fR \ ].NX R "umask command (sh)"The user file creation mask is set to the octal value.I nnn .For further information, see .MS umask 2 .If.I nnnis omitted, the current value of the mask is printed..TP\fBwait\fP.NX R "wait command (sh)"Wait for all child background processes to terminate.  The return codefrom this command is that returned upon termination of the last processbeing waited for..PD.PP.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 areinterpreted by the shell when it is invoked..PD 0.TP 11n.BI \-c \ stringIf the.B \-cflag is present, commands are read from.I string\|..TP 11n.B \-sIf the.B \-sflag is present or if no arguments remain, then commands are read fromthe standard input.  Shell output is written to file descriptor 2..TP 11n.B \-iIf the.B \-iflag is present or if the shell input and output are attached to aterminal (as told by.B gtty), then this shell is.I interactive.In this case the terminate signal SIGTERM is ignored (so that 'kill0' does not kill an interactive shell) and the interrupt signal SIGINTis caught and ignored (so that.B waitis interruptible).  For further information, see.MS sigvec 2 .In all cases SIGQUIT is ignored by the shell..PD.PPThe remaining flags and arguments are described under the.B setcommand..SH Restrictions.NX R "shell command interpreter" "restricted"If.B<<is used to provide standard input to an asynchronous process invoked by.BR & ,the shell becomes confused about naming the input document.  A garbagefile.PN /tmp/sh*is created, and the shell complains about not being able to find thefile by another name..PPThe .PN shcommand is not 8-bit clean. The .PN sh5command is 8-bit clean..PP.B VAX Only Restriction.brIf .PN sh is run from another program (by the system or exec system calls) whose maximum descriptor in use is number 10, the prompt string is not printed. .SH Diagnostics.NX R "shell command interpreter" "diagnostics"Errors detected by the shell, such as syntax errors cause the shell toreturn a nonzero exit status.  If the shell is being usednoninteractively, then execution of the shell file is abandoned.Otherwise, the shell returns the exit status of the last commandexecuted (see also.BR exit )..SH Files.PN $HOME/.profile.br.PN /tmp/sh*.br.PN /dev/null.SH See Alsocsh(1), sh5(1), test(1), execve(2), environ(7).NX R "sh command interpreter"

⌨️ 快捷键说明

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