⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rc.1

📁 早期freebsd实现
💻 1
📖 第 1 页 / 共 3 页
字号:
by default.The reason for this is that it enables an.I rcuser to grab commands from previous lines using amouse, and to present them to.I rcfor re-interpretation; the semicolonprompt is simply ignored by.IR rc .The null.Cr $prompt(2)also has itsjustification:  an.I rcscript, when typed interactively, will not leave.Cr $prompt(2) 'son the screen,and can therefore be grabbed by a mouse and placeddirectly into a file for use as a shell script, without further editingbeing necessary..TP.Cr prompt " (function)"If this function is set, then it gets executed every time.I rcis about to print.Cr "$prompt(1)" ..TP.Cr statusThe exit status of the last command.If the command exited with a numeric value,that number is the status.If the died with a signal,the status is the name of that signal; if a core filewas created, the string.Rc `` +core ''is appended.The value of.Cr $statusfor a pipeline is a list, with one entry,as above, for each process in the pipeline.For example, the command.Ds.Cr "ls | wc".De.TP\&usually sets.Cr $statusto.Cr "(0 0)" ..PPThe values of.Cr "$path" ,.Cr "$cdpath" ,and.Cr $homeare derived from the environmentvalues of.Cr "$PATH" ,.Cr "$CDPATH" ,and.Cr "$HOME" .Otherwise, they are derived fromthe environment values of.Cr $path ,.Cr $cdpathand.Cr $home .This is for compatibility with other Unix programs, like.IR sh (1)..Cr $PATHand.Cr $CDPATHare assumed to be colon-separated lists..SH FUNCTIONS.I rcfunctions are identical to.I rcscripts, except that they are storedin memory and are automatically exported into the environment.A shell function is declared as:.Ds.Cr "fn name { commands }".De.PP.I rcscans the definition until the close-brace, so the function canspan more than one line.The function definition may be removed by typing.Ds.Cr "fn name".De.PP(One or more names may be specified.With an accompanying definition, all names receive the same definition.This is sometimes usefulfor assigning the same signal handler to many signals.Without a definition, all named functions are deleted.)When a function is executed,.Cr $*is set to the arguments to thatfunction for the duration of the command.Thus a reasonable definition for.Cr "l" ,a shorthand for.IR ls (1),could be:.Ds.Cr "fn l { ls -FC $* }".De.PPbut not.Ds.Cr "fn l { ls -FC }".De.SH "INTERRUPTS AND SIGNALS".I rcrecognizes a number of signals, and allows the user to define shellfunctions which act as signal handlers..I rcby default traps.Cr SIGINTwhen it is in interactive mode..Cr SIGQUITand.Cr SIGTERMare ignored, unless.I rchas been invoked with the.Cr \-dflag.However, user-defined signal handlers may be written for these andall other signals.The way to define a signal handler is towrite a function by the name of the signal in lower case.Thus:.Ds.Cr "fn sighup { echo hangup; rm /tmp/rc$pid.*; exit }".De.PPIn addition to Unix signals,.I rcrecognizes the artificial signal.Cr SIGEXITwhich occurs as.I rcis about to exit..PPIn order to remove a signal handler's definition,remove it as though it were a regular function.For example:.Ds.Cr "fn sigint".De.PPreturns the handler of.Cr SIGINTto the default value.In order to ignore a signal, set the signal handler's value to.Cr "{}" .Thus:.Ds.Cr "fn sigint {}".De.PPcauses SIGINT to be ignored by the shell.Only signals that are being ignored are passed on to programs run by.IR rc ;signal functions are not exported..PPOn System V-based Unix systems,.I rcwill not allow you to trap.Cr SIGCLD ..SH "BUILTIN COMMANDS"Builtin commands execute in the context of the shell, but otherwisebehave exactly like other commands.Although.BR ! ,.B ~and.B @are not strictly speaking builtin commands,they can usually be used as such..TP\&\fB.\fR [\fB\-i\fR] \fIfile \fR[\fIarg ...\fR]Reads.I fileas input to.IR rcand executes its contents.With a.Cr \-iflag, input is interactive.Thus from within a shell script,.Ds.Cr ". \-i /dev/tty".De.TP\&does the ``right'' thing..TP.B breakBreaks from the innermost.Cr foror.Cr while ,as in C.It is an error to invoke.B breakoutside of a loop.(Note that there is no.B breakkeyword between commands in.Cr switchstatements, unlike C.).TP\fBbuiltin \fIcommand \fR[\fIarg ...\fR]Executes the command ignoring any function definition of thesame name.This command is present to allow functions with thesame names as builtins to use the underlying builtin or binary..TP\fBcd \fR[\fIdirectory\fR]Changes the current directory to.IR directory .The variable.Cr $cdpathis searched for possible locations of.IR directory ,analogous to the searching of.Cr $pathfor executable files.With no argument,.B cdchanges the current directory to.Cr "$home" ..TP\fBecho \fR[\fB\-n\fR] [\fB\-\|\-\fR] [\fIarg ...\fR]Prints its arguments to standard output, terminated by a newline.Arguments are separated by spaces.If the first argument is.Cr "\-n"no final newline is printed.If the first argument is.Cr "\-\|\-" ,then all other arguments are echoed literally.This is used for echoing a literal.Cr "\-n" ..TP\fBeval \fR[\fIlist\fR]Concatenates the elements of.I listwith spaces and feeds the resulting string to.I rcfor re-scanning.This is the only time input is rescanned in.IR rc ..TP\fBexec \fR[\fIarg ...\fR]Replaces.I rcwith the given command.If the exec contains only redirections,then these redirections apply to the current shelland the shell does not exit.For example,.Ds.Cr "exec >[2] err.out".De.TP\&places further output to standard error in the file.IR err.out ..TP\fBexit \fR[\fIstatus\fR]Cause the current shell to exit with the given exit.IR status .If no argument is given, the current value of.Cr $statusis used..TP\fBlimit \fR[\fB\-h\fR] [\fIresource \fR[\fIvalue\fR]]Similar to the.IR csh (1).B limitbuiltin, this command operates upon theBSD-style limits of a process.The.Cr \-hflag displays/alters the hardlimits.The resources which can be shown or altered are.BR cputime ,.BR filesize ,.BR datasize ,.BR stacksize ,.B coredumpsizeand.BR memoryuse .Forexample:.Ds.Cr "limit coredumpsize 0".De.TP\&disables core dumps..TP.B newpgrpPuts.I rcinto a new process group.This builtin is useful for making.I rcbehave like a job-control shell in a hostile environment.One example is the NeXT Terminal program, which implicitly assumesthat each shell it forks will put itself into a new process group..TP\fBreturn \fR[\fIn\fR]Returns from the current function, with status.IR n ,where.IR nis a single value or a list of possible exit statuses.Thus it is legal to have.Ds.Cr "return (sigpipe 1 2 3)".De.TP\&(This is commonly used to allow a function to return with the exit statusof a previously executed pipeline of commands.)If.IR nis omitted, then.Cr $statusis left unchanged.It is an error to invoke.B returnwhen not inside a function..TP\fBshift \fR[\fIn\fR]Deletes.I nelements from the beginning of.Cr $*and shifts the otherelements down by.IR n ..I ndefaults to 1.(Note that.Cr $0is not affected by.BR shift .).TP\fBumask \fR[\fImask\fR]Sets the current umask (see.IR umask (2))to the octal.IR mask .If no argument is present, the current mask value is printed..TP\fBwait \fR[\fIpid\fR]Waits for the specified.IR pid ,which must have been started by.IR rc .If no.I pidis specified,.I rcwaits for any child process to exit..TP\fBwhatis \fR[\fB\-s\fR] [\fB\-\|\-\fR] [\fIname ...\fR]Prints a definition of the named objects.For variables, their valuesare printed; for functions, their definitions are; and for executablefiles, path names are printed.Without arguments,.B whatisprints the values of all shell variables and functions.With a.Cr \-sargument,.B whatisalso prints out a list of available signals and their handlers (if any).Note that.B whatisoutput is suitable for input to.IR rc ;by saving the output of.B whatisin a file, it should be possible to recreate the state of.I rcby sourcing this file with a.Cr .command.Another note:.Cr "whatis -s > file"cannot be used to store the state of.IR rc 'ssignal handlers in a file, because builtins with redirectionsare run in a subshell, and.I rcalways restores signal handlers to their default value after a.Cr fork() ..TP\&Since.B whatisuses.IR getopt (3)to parse its arguments, you can use the special argument.Cr "\-\|\-"to terminate its options.This allows you to use names beginning with a dash, such asthe.IR history (1)commands.For example,.Ds.Cr "whatis \-\|\- \-p".De.SH GRAMMARHere is.IR rc 'sgrammar, edited to remove semantic actions..Ds.ft \*(Cf%term ANDAND BACKBACK BANG CASE COUNT DUP ELSE END FLAT FN FOR IF IN%term OROR PIPE REDIR SUB SUBSHELL SWITCH TWIDDLE WHILE WORD HUH%left WHILE ')' ELSE%left ANDAND OROR '\en'%left BANG SUBSHELL%left PIPE%right '$'%left SUB%start rc%%rc: line end	| error endend: END /* EOF */ | '\en'cmdsa: cmd ';' | cmd '&'line: cmd | cmdsa linebody: cmd | cmdsan bodycmdsan: cmdsa | cmd '\en'brace: '{' body '}'paren: '(' body ')'assign: first '=' wordepilog: /* empty */ | redir epilogredir: DUP | REDIR wordcase: CASE words ';' | CASE words '\en'cbody: cmd | case cbody | cmdsan cbodyiftail: cmd	%prec ELSE	| brace ELSE optnl cmdcmd	: /* empty */	%prec WHILE	| simple	| brace epilog	| IF paren optnl iftail	| FOR '(' word IN words ')' optnl cmd	| FOR '(' word ')' optnl cmd	| WHILE paren optnl cmd		| SWITCH '(' word ')' optnl '{' cbody '}'	| TWIDDLE optcaret word words	| cmd ANDAND optnl cmd	| cmd OROR optnl cmd 	| cmd PIPE optnl cmd	| redir cmd	%prec BANG	| assign cmd	%prec BANG	| BANG optcaret cmd	| SUBSHELL optcaret cmd	| FN words brace	| FN wordsoptcaret: /* empty */ | '^'simple: first | simple word | simple redirfirst: comword | first '^' swordsword: comword | keywordword: sword | word '^' swordcomword: '$' sword	| '$' sword SUB words ')'	| COUNT sword	| FLAT sword	| '`' sword	| '`' brace	| BACKBACK word	brace | BACKBACK word sword	| '(' words ')'	| REDIR brace	| WORDkeyword: FOR | IN | WHILE | IF | SWITCH	| FN | ELSE | CASE | TWIDDLE | BANG | SUBSHELLwords: /* empty */ | words wordoptnl: /* empty */ | optnl '\en'.ft R.De.SH FILES.Cr $HOME/.rcrc ,.Cr /tmp/rc* ,.Cr /dev/null.SH CREDITS.I rcwas written by Byron Rakitzis, with valuable helpfrom Paul Haahr, Hugh Redelmeier and David Sanderson.The design of this shell has been copied from the.I rcthat Tom Duff wrote at Bell Labs..SH BUGSOn systems that support.Cr /dev/fd ,.Cr <{foo}style redirection is implemented that way.However, on other systems it is implemented with named pipes,and it is sometimespossible to foil.I rcinto removing the FIFO it places in.Cr /tmpprematurely, or it is even possible to cause.I rcto hang..PPThe functionality of.B shiftshould be available for variables other than.Cr "$*" ..PP.B echois built in only for performance reasons, which is a bad idea..PPThere should be a way to avoid exporting a variable..PPThe.Cr $^varnotation for flattening should allow for using an arbitraryseparating character, not just space..PPBug reports should be mailed to.Cr "byron@archone.tamu.edu" ..SH INCOMPATIBILITIESHere is a list of features which distinguish this incarnation of.I rcfrom the one described in the Bell Labs manual pages:.PPThe treatment of.Cr if - elseis different in the v10.IR rc :that version uses an.Cr "if not"clause which gets executedif the preceding.Cr iftest does not succeed..PPBackquotes are slightly different in v10.IR rc :a backquote must always be followed by a left-brace.This restriction is not present for single-word commands in this.IR rc ..PPThe following are all new with this version of.IR rc :The.Cr \-noption,the list flattening operator,here strings (they facilitate exporting of functionswith here documents into the environment),the.B returnand.B breakkeywords,the.B echobuiltin,the support for the GNU.IR readline (3)library andthe support for the.Cr promptfunction.This.I rcalso sets.Cr $0to the name of a function being executed/filebeing sourced..SH "SEE ALSO"``rc \(em A Shell for Plan 9 and UNIX Systems'',Unix Research System,10th Edition,vol. 2. (Saunders College Publishing)(This paper is also distributed with this.I rcin PostScript form.).PP.IR history (1)

⌨️ 快捷键说明

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