📄 csh.1
字号:
Standing alone, i.e., `~' it expands to the invokers home directory as reflectedin the value of the variable.Ar home .When followed by a name consisting of letters, digits and `\-' characters,the shell searches for a user with that name and substitutes theirhome directory; thus `~ken' might expand to `/usr/ken' and `~ken/chmach'to `/usr/ken/chmach'.If the character `~' is followed by a character other than a letter or `/'or does not appear at the beginning of a word,it is left undisturbed..PpThe metanotation `a{b,c,d}e' is a shorthand for `abe ace ade'.Left to right order is preserved, with results of matches being sortedseparately at a low level to preserve this order.This construct may be nested.Thus, `~source/s1/{oldls,ls}.c' expands to`/usr/source/s1/oldls.c /usr/source/s1/ls.c'without chance of errorif the home directory for `source' is `/usr/source'.Similarly `../{memo,*box}' might expand to `../memo ../box ../mbox'.(Note that `memo' was not sorted with the results of the match to `*box'.)As a special case `{', `}' and `{}' are passed undisturbed..Ss Input/outputThe standard input and the standard output of a command may be redirectedwith the following syntax:.Pp.Bl -tag -width Ds -compact -offset indent.It < nameOpen file.Ar name(which is first variable, command and filename expanded) as the standardinput..It << wordRead the shell input up to a line that is identical to.Ar word ..Ar Wordis not subjected to variable, filename or command substitution,and each input line is compared to.Ar wordbefore any substitutions are done on the input line.Unless a quoting `\e', `"', `\*(aa' or `\*(ga' appears in.Ar word ,variable and command substitution is performed on the intervening lines,allowing `\e' to quote `$', `\e' and `\*(ga'.Commands that are substituted have all blanks, tabs, and newlinespreserved, except for the final newline which is dropped.The resultant text is placed in an anonymous temporary file thatis given to the command as its standard input..It > name.It >! name.It >& name.It >&! nameThe file.Ar nameis used as the standard output.If the file does not exist then it is created;if the file exists, it is truncated; its previous contents are lost..PpIf the variable.Ar noclobberis set, then the file must not exist or be a character special file (e.g., aterminal or `/dev/null') or an error results.This helps prevent accidental destruction of files.Here, the `!' forms can be used to suppress this check..PpThe forms involving `&' route the standard error output into the specifiedfile as well as the standard output..Ar Nameis expanded in the same way as `<' input filenames are..It >> name.It >>& name.It >>! name.It >>&! nameUses file.Ar nameas the standard output;like `>' but places output at the end of the file.If the variable.Ar noclobberis set, then it is an error for the file not to exist unlessone of the `!' forms is given.Otherwise similar to `>'..El.PpA command receives the environment in which the shell wasinvoked as modified by the input-output parameters andthe presence of the command in a pipeline.Thus, unlike some previous shells, commands run from a file of shell commandshave 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 permits shell command scripts to function as components of pipelinesand allows the shell to block read its input.Note that the default standard input for a command run detached is.Ar notmodified to be the empty file.Pa /dev/null ;instead the standard inputremains as the original standard input of the shell. If this is a terminaland if the process attempts to read from the terminal, then the processwill block and the user will be notified (see.Sx Jobsabove)..PpThe standard error output may be directed througha pipe with the standard output.Simply use the form `\&|&' instead of just `\&|'..Ss ExpressionsSeveral of the builtin commands (to be described later)take expressions, in which the operators are similar to those of C, withthe same precedence.These expressions appear in the.Nm @,.Ar exit ,.Ar if ,and.Ar whilecommands.The following operators are available:.Bd -ragged -offset indent\&|\&| && \&| \*(ua & == != =~ !~ <= >=< > << >> + \- * / % ! ~ ( ).Ed.PpHere the precedence increases to the right,`==' `!=' `=~' and `!~', `<=' `>=' `<' and `>', `<<' and `>>', `+' and `\-',`*' `/' and `%' being, in groups, at the same level.The `==' `!=' `=~' and `!~' operators compare their arguments as strings;all others operate on numbers.The operators `=~' and `!~' are like `!=' and `==' except that the righthand side is a.Ar pattern(containing, e.g., `*'s, `?'s and instances of `[...]')against which the left hand operand is matched. This reduces theneed for use of the.Ar switchstatement in shell scripts when all that is really needed is pattern matching..PpStrings that begin with `0' are considered octal numbers.Null or missing arguments are considered `0'.The result of all expressions are strings,which represent decimal numbers.It is important to note that no two components of an expression can appearin the same word; except when adjacent to components of expressions thatare syntactically significant to the parser (`&' `\&|' `<' `>' `(' `)'),they should be surrounded by spaces..PpAlso available in expressions as primitive operands are command executionsenclosed in `{' and `}'and file enquiries of the form.Fl l.Ar namewhere.Ic lis one of:.Bd -literal -offset indentr read accessw write accessx execute accesse existenceo ownershipz zero sizef plain filed directory.Ed.PpThe specified name is command and filename expanded and then testedto see if it has the specified relationship to the real user.If the file does not exist or is inaccessible then all enquiries returnfalse, i.e., `0'.Command executions succeed, returning true, i.e., `1',if the command exits with status 0, otherwise they fail, returningfalse, i.e., `0'.If more detailed status information is required then the commandshould be executed outside an expression and the variable.Ar statusexamined..Ss Control flowThe shell contains several commands that can be used to regulate theflow of control in command files (shell scripts) and(in limited but useful ways) from terminal input.These commands all operate by forcing the shell to reread or skip in itsinput and, because of the implementation, restrict the placement of someof the commands..PpThe.Ic foreach ,.Ic switch ,and.Ic whilestatements, as well as the.Ic if\-then\-elseform of the.Ic ifstatement require that the major keywords appear in a single simple commandon an input line as shown below..PpIf the shell's input is not seekable,the shell buffers up input whenever a loop is being readand performs seeks in this internal buffer to accomplish the rereadingimplied by the loop.(To the extent that this allows, backward goto's will succeed onnon-seekable inputs.).Ss 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..Pp.Bl -tag -width Ds -compact -offset indent.It Ic alias.It Ic alias Ar name.It Ic alias Ar name wordlistThe first form prints all aliases.The second form prints the alias for name.The final form assigns the specified.Ar wordlistas the alias of.Ar name ;.Ar wordlistis command and filename substituted..Ar Nameis not allowed to be.Ar aliasor.Ar unalias ..Pp.It Ic allocShows the amount of dynamic memory acquired, broken down into used andfree memory.With an argument shows the number of free and used blocks in each sizecategory. The categories start at size 8 and double at each step.This command's output may vary across system types, sincesystems other than the VAX may use a different memory allocator..Pp.It Ic bg.It Ic bg \&% Ns Ar job ...Puts the current or specified jobs into the background, continuing themif they were stopped..Pp.It Ic breakCauses execution to resume after the.Ic endof the nearest enclosing.Ic foreachor.Ic while .The remaining commands on the current line are executed.Multi-level breaks are thus possible by writing them all on one line..Pp.It Ic breakswCauses a break from a.Ic switch ,resuming after the.Ic endsw ..Pp.It Ic case Ar label :A label in a.Ic switchstatement as discussed below..Pp.It Ic cd.It Ic cd Ar name.It Ic chdir.It Ic chdir Ar nameChange the shell's working directory to directory.Ar name .If no argument is given then change to the home directory of the user.If.Ar nameis not found as a subdirectory of the current directory (and does not beginwith `/', `./' or `../'), then eachcomponent of the variable.Ic cdpathis checked to see if it has a subdirectory.Ar name .Finally, if all else fails but.Ar nameis a shell variable whose value begins with `/', then thisis tried to see if it is a directory..Pp.It Ic continueContinue execution of the nearest enclosing.Ic whileor.Ic foreach .The rest of the commands on the current line are executed..Pp.It Ic default :Labels the default case in a.Ic switchstatement.The default should come after all.Ic caselabels..Pp.It Ic dirsPrints the directory stack; the top of the stack is at the left,the first directory in the stack being the current directory..Pp.It Ic echo Ar wordlist.It Ic echo Fl n Ar wordlistThe specified words are written to the shell's standard output, separatedby spaces, and terminated with a newline unless the.Fl noption is specified..Pp.It Ic else.It Ic end.It Ic endif.It Ic endswSee the description of the.Ic foreach ,.Ic if ,.Ic switch ,and.Ic whilestatements below..Pp.It Ic eval Ar arg ...(As in.Xr sh 1 . )The arguments are read as input to the shell and the resultingcommand(s) executed in the context of the current shell.This is usually used to execute commandsgenerated as the result of command or variable substitution, sinceparsing occurs before these substitutions. See.Xr tset 1for an example of using.Ic eval ..Pp.It Ic exec Ar commandThe specified command is executed in place of the current shell..Pp.It Ic exit.It Ic exit Ar (expr )The shell exits either with the value of the.Ic statusvariable (first form) or with the value of the specified.Ic expr(second form)..Pp.It Ic fg.It Ic fg % Ns Ar job ...Brings the current or specified jobs into the foreground, continuing them ifthey were stopped..Pp.It Ic foreach Ar name (wordlist).It ....It Ic endThe variable.Ic nameis successively set to each member of.Ic wordlistand the sequence of commands between this command and the matching.Ic endare executed.(Both.Ic foreachand.Ic endmust appear alone on separate lines.)The builtin command.Ic continuemay be used to continue the loop prematurely and the builtincommand.Ic breakto terminate it prematurely.When this command is read from the terminal, the loop is read onceprompting with `?' before any statements in the loop are executed.If you make a mistake typing in a loop at the terminal you can rub it out..Pp.It Ic glob Ar wordlistLike.Ic echobut no `\e' escapes are recognized and words are delimitedby null characters in the output.Useful for programs that wish to use the shell to filename expand a listof words..Pp.It Ic goto Ar wordThe specified.Ic wordis filename and command expanded to yield a string of the form `label'.The shell rewinds its input as much as possibleand searches for a line of the form `label:'possibly preceded by blanks or tabs.Execution continues after the specified line..Pp.It Ic hashstatPrint a statistics line showing how effective the internal hashtable has been at locating commands (and avoiding.Ic exec Ns \'s ) .An.Ic execis attempted for each component of the.Em pathwhere the hash function indicates a possible hit, and in each componentthat does not begin with a `/'..Pp.It Ic history.It Ic history Ar n.It Ic history Fl r Ar n.It Ic history Fl h Ar nDisplays the history event list; if.Ar nis given only the.Ar nmost recent events are printed.The.Fl roption reverses the order of printout to be most recent firstinstead of oldest first.The.Fl hoption causes the history list to be printed without leading numbers.This format produces files suitable for sourcing using the \-hoption to.Ic source ..Pp.It Ic if ( Ar expr ) No commandIf the specified expression evaluates true, then the single
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -