📄 rc.1
字号:
.\" rc.1.\"-------.\" Man page portability notes.\".\" These are some notes on conventions to maintain for greatest.\" portability of this man page to various other versions of.\" nroff..\".\" When you want a \ to appear in the output, use \e in the man page..\" (NOTE this comes up in the rc grammar, where to print out '\n' the.\" man page must contain '\en'.).\".\" Evidently not all versions of nroff allow the omission of the.\" terminal " on a macro argument. Thus what could be written.\".\" .Cr "exec >[2] err.out.\".\" in true nroffs must be written.\".\" .Cr "exec >[2] err.out".\".\" instead..\".\" Use symbolic font names (e.g. R, I, B) instead of the standard.\" font positions 1, 2, 3. Note that for Xf to work the standard.\" font names must be single characters..\".\" Not all man macros have the RS and RE requests (I altered the Ds.\" and De macros and the calls to Ds accordingly)..\".\" Thanks to Michael Haardt (u31b3hs@cip-s01.informatik.rwth-aachen.de).\" for pointing out these problems..\".\" Note that sentences should end at the end of a line. nroff and.\" troff will supply the correct intersentence spacing, but only if.\" the sentences end at the end of a line. Explicit spaces, if given,.\" are apparently honored and the normal intersentence spacing is.\" supressed..\".\" DaviD W. Sanderson.\"-------.\" Dd distance to space vertically before a "display".\" These are what n/troff use for interparagraph distance.\"-------.if t .nr Dd .4v.if n .nr Dd 1v.\"-------.\" Ds begin a display, indented .5 inches from the surrounding text..\".\" Note that uses of Ds and De may NOT be nested..\"-------.de Ds.\" .RS \\$1.sp \\n(Ddu.in +0.5i.nf...\"-------.\" De end a display (no trailing vertical spacing).\"-------.de De.fi.in.\" .RE...\"-------.\" I stole the Xf macro from the -man macros on my machine (originally.\" "}S", I renamed it so that it won't conflict)..\"-------.\" Set Cf to the name of the constant width font..\" It will be "C" or "(CW", typically..\" NOTEZ BIEN the lines defining Cf must have no trailing white space:.\"-------.if t .ds Cf C.if n .ds Cf R.\"-------.\" Rc - Alternate Roman and Courier.\"-------.de Rc.Xf R \\*(Cf \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"...\"-------.\" Ic - Alternate Italic and Courier.\"-------.de Ic.Xf I \\*(Cf \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"...\"-------.\" Bc - Alternate Bold and Courier.\"-------.de Bc.Xf B \\*(Cf \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"...\"-------.\" Cr - Alternate Courier and Roman.\"-------.de Cr.Xf \\*(Cf R \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"...\"-------.\" Ci - Alternate Courier and Italic.\"-------.de Ci.Xf \\*(Cf I \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"...\"-------.\" Cb - Alternate Courier and Bold.\"-------.de Cb.Xf \\*(Cf B \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"...\"-------.\" Xf - Alternate fonts.\".\" \$1 - first font.\" \$2 - second font.\" \$3 - desired word with embedded font changes, built up by recursion.\" \$4 - text for first font.\" \$5 - \$9 - remaining args.\".\" Every time we are called:.\".\" If there is something in \$4.\" then Call ourself with the fonts switched,.\" with a new word made of the current word (\$3) and \$4.\" rendered in the first font,.\" and with the remaining args following \$4..\" else We are done recursing. \$3 holds the desired output.\" word. We emit \$3, change to Roman font, and restore.\" the point size to the default..\" fi.\".\" Use Xi to add a little bit of space after italic text..\"-------.de Xf.ds Xi.\"-------.\" I used to test for the italic font both by its font position.\" and its name. Now just test by its name..\".\" .if "\\$1"2" .if !"\\$5"" .ds Xi \^.\"-------.if "\\$1"I" .if !"\\$5"" .ds Xi \^.\"-------.\" This is my original code to deal with the recursion..\" Evidently some nroffs can't deal with it..\"-------.\" .ie !"\\$4"" \{\.\" . Xf \\$2 \\$1 "\\$3\\f\\$1\\$4\\*(Xi" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9".\" .\}.\" .el \{\\$3.\" . ft R \" Restore the default font, since we don't know.\" . \" what the last font change was..\" . ps 10 \" Restore the default point size, since it might.\" . \" have been changed by an argument to this macro..\" .\}.\"-------.\" Here is more portable (though less pretty) code to deal with.\" the recursion..\"-------.if !"\\$4"" .Xf \\$2 \\$1 "\\$3\\f\\$1\\$4\\*(Xi" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9".if "\\$4"" \\$3\fR\s10...TH RC 1 "28 April 1991".SH NAMErc \- shell.SH SYNOPSIS.B rc.RB [ \-eixvldnpo ].RB [ \-c.IR command ].RI [ arguments ].SH DESCRIPTION.I rcis a command interpreter and programming language similar to.IR sh (1).It is based on the AT&T Plan 9 shell of the same name.The shell offers a C-like syntax (much more so than the C shell),and a powerful mechanism for manipulating variables.It is reasonably small and reasonably fast,especially when compared to contemporary shells.Its use is intended to be interactive,but the language lends itself well to scripts..SH OPTIONS.TP.Cr \-eIf the.Cr \-eoption is present, then.I rcwill exit if the exit status of a command is false (nonzero)..I rcwill not exit, however, if a conditional fails, e.g., an.Cr if()command..TP.Cr \-iIf the.Cr \-ioption is present or if the input to.I rcis from a terminal (as determined by.IR isatty (3))then.I rcwill be in.I interactivemode.That is, a prompt (from.Cr $prompt(1)\^ )will be printed before aninput line is taken, and.I rcwill ignore the signals.Cr SIGINTand.Cr SIGQUIT ..TP.Cr \-xThis option will make.I rcprint every command on standard error before it is executed.It can be useful for debugging.I rcscripts..TP.Cr \-vThis option will echo input to.I rcon standard error as it is read..TP.Cr \-lIf the.Cr \-loption is present, or if.IR rc 's.Cr argv[0][0]is a dash.Rc ( \- ),then.I rcwill behave as a login shell.That is, it will try to run commands present in.Cr $home/.rcrc ,if this file exists, before reading any other input..TP.Cr \-dThis flag causes.I rcnot to ignore.Cr SIGQUITor.Cr SIGTERM .Thus.I rccan be made to dump core if sent.Cr SIGQUIT .This option is only useful for debugging.IR rc ..TP.Cr \-nThis flag causes.I rcto read its input and parse it, but not to execute any commands.This is useful for syntax checking on scripts.If used in combination with the.Cr \-xoption,.I rcwill print each command as it is parsed in a form similar to the oneused for exporting functions into the environment..TP.Cr \-pThis flag prevents.I rcfrom initializing shell functions from the environment.This allows.I rcto run in a protected mode, whereby it becomes more difficult foran.I rcscript to be subverted by placing false commands in the environment.(Note that this presence of this option does NOT mean that it is safe torun setuid.I rcscripts; the usual caveats about the setuid bit still apply.).TP.Cr \-oThis flag prevents the usual practice of trying to open.Cr /dev/nullon file descriptors 0, 1, and 2, if any of those descriptorsare inherited closed..TP.Cr \-cIf.Cr \-cis present, commands are executed from the immediately followingargument.Any further arguments to.I rcare placed in.Cr $* ..PP.SH COMMANDSA simple command is a sequence of words, separated by white space(space and tab) characters that ends with a newline, semicolon.Rc ( ; ),or ampersand.Rc ( & ).The first word of a command is the name of that command.If the name begins with.Cr / ,.Cr ./ ,or.Cr ../ ,then the name is used as an absolute pathname referring to an executable file.Otherwise, the name of the command is looked up in a tableof shell functions, builtin commands,or as a file in the directories named by.Cr $path ..SS "Background Tasks"A command ending with a.Cr &is run in the background; that is,the shell returns immediately rather than waiting for the command tocomplete.Background commands have.Cr /dev/nullconnected to their standard input unless an explicit redirection forstandard input is used..SS "Subshells"A command prefixed with an at-sign.Rc ( @ )is executed in a subshell.This insulates the parent shell from the effectsof state changing operations such as a.B cdor a variable assignment.For example:.Ds.Cr "@ {cd ..; make}".De.PPwill run.IR make (1)in the parent directory.Rc ( .. ),but leaves the shell running in the current directory..SS "Line continuation"A long logical line may be continued over several physical lines byterminating each line (except the last) with a backslash.Rc ( \e ).The backslash-newline sequence is treated as a space.A backslash is not otherwise special to.IR rc .(In addition,inside quotes a backslash loses its special meaningeven when it is followed by a newline.).SS Quoting.IR rcinterprets several characters specially; special charactersautomatically terminate words.The following characters are special:.Ds.Cr "# ; & | ^ $ = \` ' { } ( ) < >".De.PPThe single quote.Rc ( ' )prevents special treatment of any character other than itself.All characters, including control characters, newlines,and backslashes between two quote characters are treated as anuninterpreted string.A quote character itself may be quoted by placing two quotes in a row.The minimal sequence needed to enter the quote character is.Cr '''' .The empty string is represented by.Cr '' .Thus:.Ds.Cr "echo 'What''s the plan, Stan?'".De.PPprints out.Ds.Cr "What's the plan, Stan?".De.PPThe number sign.Rc ( # )begins a comment in.IR rc .All characters up to but not including the next newline are ignored.Note that backslash continuation does not work inside a comment,i.e.,the backslash is ignored along with everything else..SS GroupingZero or more commands may be grouped within braces.Rc (`` { ''and.Rc `` } ''),and are then treated as one command.Braces do not otherwise define scope;they are used only for command grouping.In particular, be wary of the command:.Ds.Cr "for (i) {".Cr " command".Cr "} | command".De.PPSince pipe binds tighter than.Cr for ,this command does not perform what the user expects it to.Instead, enclose the whole.Cr forstatement in braces:.Ds.Cr "{for (i) command} | command".De.PPFortunately,.IR rc 'sgrammar is simple enough that a (confident) user canunderstand it by examining the skeletal.IR yacc (1)grammarat the end of this man page (see the section entitled.BR GRAMMAR )..SS "Input and output".PPThe standard output may be redirected to a file with.Ds.Cr "command > file".De.PPand the standard input may be taken from a file with.Ds.Cr "command < file".De.PPFile descriptors other than 0 and 1 may be specified also.For example, to redirect standard error to a file, use:.Ds.Cr "command >[2] file".De.PPIn order to duplicate a file descriptor, use.Ci >[ n = m ]\fR.Thus to redirect both standard output and standard errorto the same file, use.Ds.Cr "command > file >[2=1]".De.PPTo close a file descriptor that may be open, use.Ci >[ n =]\fR.For example, toclose file descriptor 7:.Ds.Cr "command >[7=]".De.PPIn order to place the output of a command at the end of an alreadyexisting file, use:.Ds.Cr "command >> file".De.PPIf the file does not exist, then it is created..PP``Here documents'' are supported as in.I shwith the use of.Ds.Cr "command << 'eof-marker'".De.PPIf the end-of-file marker is enclosed in quotes,then no variable substitution occurs inside the here document.Otherwise, every variable is substitutedby its space-separated-list value (see.BR "Flat Lists" ,below),and if a.Cr ^character follows a variable name, it is deleted.This allows the unambiguous use of variables adjacent to text, as in.Ds.Cr $variable^follow.DeTo include a literal.Cr $in a here document when an unquoted end-of-file marker is being used,enter it as.Cr $$ ..PPAdditionally,.I rcsupports ``here strings'', which are like here documents,except that input is taken directly from a string on the command line.Its use is illustrated here:.Ds.Cr "cat <<< 'this is a here string' | wc".De.PP(This feature enables.I rcto export functions using here documents into the environment;the author does not expect users to find this feature useful.).SS PipesTwo or more commands may be combined in a pipeline by placing thevertical bar.Rc ( \||\| )between them.The standard output (file descriptor 1)of the command on the left is tied to the standard input (filedescriptor 0) of the command on the right.The notation.Ci |[ n = m ]indicates that file descriptor.I nof the left process is connected tofile descriptor.I mof the right process..Ci |[ n ]is a shorthand for.Ci |[ n =0]\fR.As an example, to pipe the standard error of a command to.IR wc (1),use:.Ds.Cr "command |[2] wc".De.PPThe exit status of a pipeline is considered true if and only if everycommand in the pipeline exits true..SS "Commands as Arguments"Some commands, like.IR cmp (1)or.IR diff (1),take their arguments on the commandline, and do not read input from standard input.It is convenientsometimes to build nonlinear pipelines so that a command like.I cmpcan read the output of two other commands at once..I rcdoes it like this:.Ds.Cr "cmp <{command} <{command}".De.PPcompares the output of the two commands in braces.A note: since this form ofredirection is implemented with some kind of pipe, and since one cannot.IR lseek (2)on a pipe, commands that use.IR lseek (2)will hang.For example,most versions of.IR diff (1)use.IR lseek (2)on their inputs..PPData can be sent down a pipe to several commands using.IR tee (1)and the output version of this notation:.Ds.Cr "echo hi there | tee >{sed 's/^/p1 /'} >{sed 's/^/p2 /'}".De.SH "CONTROL STRUCTURES"The following may be used for control flow in.IR rc :.SS "If-else Statements".PD 0.sp.Ci "if (" test ") {".br.I " cmd".br.TP.Ci "} else " cmdThe.I testis executed, and if its return status is zero, the firstcommand is executed, otherwise the second is.Braces are not mandatory around the commands.However, an.Cr elsestatement is valid only if itfollows a close-brace on the same line.Otherwise, the.Cr ifis taken to be a simple-if:.Ds.Cr "if (test)".Cr " command".De.PD.SS "While and For Loops".TP.Ci "while (" test ) " cmd".I rcexecutes the.I testand performs the command as long as the.I testis true..TP.Ci "for (" var " in" " list" ) " cmd".I rcsets.I varto each element of.I list(which may contain variables and backquote substitutions) and runs.IR cmd .If.Rc `` in.IR list ''is omitted, then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -