UNIX Reference Manual (794271), страница 4
Текст из файла (страница 4)
This helps prevent accidental destructionof files. Here, the ‘!’ forms can be used to suppress this check.The forms involving ‘&’ route the standard error output into the specified file as well as thestandard output. Name is expanded in the same way as ‘<’ input filenames are.>> name>>& name>>! name>>&! nameUses file name as the standard output; like ‘>’ but places output at the end of the file. If thevariable noclobber is set, then it is an error for the file not to exist unless one of the ‘!’forms is given. Otherwise similar to ‘>’.A command receives the environment in which the shell was invoked as modified by the input-output parameters and the presence of the command in a pipeline. Thus, unlike some previous shells, commands run froma file of shell commands have no access to the text of the commands by default; instead they receive the original standard input of the shell.
The ‘<<’ mechanism should be used to present inline data. This permitsshell command scripts to function as components of pipelines and allows the shell to block read its input.Note that the default standard input for a command run detached is not modified to be the empty file/dev/null; instead the standard input remains as the original standard input of the shell. If this is a terminal and if the process attempts to read from the terminal, then the process will block and the user will be notified (see Jobs above).The standard error output may be directed through a pipe with the standard output.
Simply use the form ‘|&’instead of just ‘|’.4th Berkeley DistributionJanuary 21, 19949CSH ( 1 )UNIX Reference ManualCSH ( 1 )ExpressionsSeveral of the builtin commands (to be described later) take expressions, in which the operators are similar tothose of C, with the same precedence. These expressions appear in the @, exit, if, and while commands. The following operators are available:|| && | ↑ & == != =˜ !˜ <= >= < > << >> + − ∗ / % ! ˜ ( )Here the precedence increases to the right, ‘==’ ‘!=’ ‘=˜’ and ‘!˜’, ‘<=’ ‘>=’ ‘<’ and ‘>’, ‘<<’ and ‘>>’, ‘+’and ‘−’, ‘∗’ ‘/’ and ‘%’ being, in groups, at the same level. The ‘==’ ‘!=’ ‘=˜’ and ‘!˜’ operators comparetheir arguments as strings; all others operate on numbers.
The operators ‘=˜’ and ‘!˜’ are like ‘!=’ and ‘==’except that the right hand side is a pattern (containing, e.g., ‘∗’s, ‘?’s and instances of ‘[...]’) againstwhich the left hand operand is matched. This reduces the need for use of the switch statement in shellscripts when all that is really needed is pattern matching.Strings that begin with ‘0’ are considered octal numbers. Null or missing arguments are considered ‘0’. Theresult of all expressions are strings, which represent decimal numbers.
It is important to note that no twocomponents of an expression can appear in the same word; except when adjacent to components of expressions that are syntactically significant to the parser (‘&’ ‘|’ ‘<’ ‘>’ ‘(’ ‘)’), they should be surrounded byspaces.Also available in expressions as primitive operands are command executions enclosed in ‘{’ and ‘}’ and fileenquiries of the form −l name where l is one of:rwxeozfdread accesswrite accessexecute accessexistenceownershipzero sizeplain filedirectoryThe specified name is command and filename expanded and then tested to see if it has the specified relationship to the real user. If the file does not exist or is inaccessible then all enquiries return false, i.e., ‘0’. Command executions succeed, returning true, i.e., ‘1’, if the command exits with status 0, otherwise they fail, returning false, i.e., ‘0’. If more detailed status information is required then the command should be executedoutside an expression and the variable status examined.Control flowThe shell contains several commands that can be used to regulate the flow of control in command files (shellscripts) and (in limited but useful ways) from terminal input.
These commands all operate by forcing theshell to reread or skip in its input and, because of the implementation, restrict the placement of some of thecommands.The foreach, switch, and while statements, as well as the if−then−else form of the if statementrequire that the major keywords appear in a single simple command on an input line as shown below.If the shell’s input is not seekable, the shell buffers up input whenever a loop is being read and performsseeks in this internal buffer to accomplish the rereading implied by the loop. (To the extent that this allows,backward goto’s will succeed on non-seekable inputs.)Builtin commandsBuiltin commands are executed within the shell.
If a builtin command occurs as any component of a pipelineexcept the last then it is executed in a subshell.4th Berkeley DistributionJanuary 21, 199410CSH ( 1 )UNIX Reference ManualCSH ( 1 )aliasalias namealias name wordlistThe first form prints all aliases. The second form prints the alias for name. The final formassigns the specified wordlist as the alias of name; wordlist is command and filename substituted. Name is not allowed to be alias or unalias.alloc Shows the amount of dynamic memory acquired, broken down into used and free memory.With an argument shows the number of free and used blocks in each size category.
The categories start at size 8 and double at each step. This command’s output may vary across system types, since systems other than the VAX may use a different memory allocator.bgbg %job ...Puts the current or specified jobs into the background, continuing them if they were stopped.break Causes execution to resume after the end of the nearest enclosing foreach or while. Theremaining commands on the current line are executed.
Multi-level breaks are thus possibleby writing them all on one line.breakswCauses a break from a switch, resuming after the endsw.case label:A label in a switch statement as discussed below.cdcd namechdirchdir nameChange the shell’s working directory to directory name. If no argument is given then changeto the home directory of the user. If name is not found as a subdirectory of the current directory (and does not begin with ‘/’, ‘./’ or ‘../’), then each component of the variablecdpath is checked to see if it has a subdirectory name. Finally, if all else fails but name isa shell variable whose value begins with ‘/’, then this is tried to see if it is a directory.continueContinue execution of the nearest enclosing while or foreach.
The rest of the commandson the current line are executed.default:Labels the default case in a switch statement. The default should come after all case labels.dirsPrints the directory stack; the top of the stack is at the left, the first directory in the stack being the current directory.echo wordlistecho −n wordlistThe specified words are written to the shell’s standard output, separated by spaces, and terminated with a newline unless the −n option is specified.elseendendifendsw See the description of the foreach, if, switch, and while statements below.4th Berkeley DistributionJanuary 21, 199411CSH ( 1 )UNIX Reference ManualCSH ( 1 )eval arg ...(As in sh(1).) The arguments are read as input to the shell and the resulting command(s) executed in the context of the current shell.
This is usually used to execute commands generated as the result of command or variable substitution, since parsing occurs before these substitutions. See tset(1) for an example of using eval.exec commandThe specified command is executed in place of the current shell.exitexit (expr)The shell exits either with the value of the status variable (first form) or with the value ofthe specified expr (second form).fgfg %job ...Brings the current or specified jobs into the foreground, continuing them if they werestopped.foreach name (wordlist)...endThe variable name is successively set to each member of wordlist and the sequence ofcommands between this command and the matching end are executed. (Both foreachand end must appear alone on separate lines.) The builtin command continue may beused to continue the loop prematurely and the builtin command break to terminate it prematurely.
When this command is read from the terminal, the loop is read once promptingwith ‘?’ before any statements in the loop are executed. If you make a mistake typing in aloop at the terminal you can rub it out.glob wordlistLike echo but no ‘\’ escapes are recognized and words are delimited by null characters inthe output. Useful for programs that wish to use the shell to filename expand a list of words.goto wordThe specified word is filename and command expanded to yield a string of the form ‘label’.The shell rewinds its input as much as possible and searches for a line of the form ‘label:’possibly preceded by blanks or tabs. Execution continues after the specified line.hashstatPrint a statistics line showing how effective the internal hash table has been at locating commands (and avoiding exec´s).
An exec is attempted for each component of the path wherethe hash function indicates a possible hit, and in each component that does not begin with a‘/’.historyhistory nhistory −r nhistory −h nDisplays the history event list; if n is given only the n most recent events are printed. The−r option reverses the order of printout to be most recent first instead of oldest first. The−h option causes the history list to be printed without leading numbers.
This format produces files suitable for sourcing using the −h option to source.if (expr) commandIf the specified expression evaluates true, then the single command with arguments is executed. Variable substitution on command happens early, at the same time it does for the4th Berkeley DistributionJanuary 21, 199412CSH ( 1 )UNIX Reference ManualCSH ( 1 )rest of the if command. Command must be a simple command, not a pipeline, a commandlist, or a parenthesized command list.
Input/output redirection occurs even if expr is false,i.e., when command is not executed (this is a bug).if (expr) then...else if (expr2) then...else...endif If the specified expr is true then the commands up to the first else are executed; otherwiseif expr2 is true then the commands up to the second else are executed, etc. Any numberof else-if pairs are possible; only one endif is needed. The else part is likewise optional. (The words else and endif must appear at the beginning of input lines; the ifmust appear alone on its input line or after an else.)jobsjobs −lLists the active jobs; the −l option lists process id’s in addition to the normal information.killkillkillkilllimitlimitlimitlimitlimitlimit%jobpid−sig pid ...−lSends either the TERM (terminate) signal or the specified signal to the specified jobs or processes.