csh.1

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

1
2,332
字号
.\" SCCSID: @(#)csh.1	3.4	9/14/88.de sh.br.ne 5.PP\fB\\$1\fR.PP...if n .ds ua \o'^|'.if t .ds ua \(ua.if n .ds aa '.if t .ds aa \(aa.if n .ds ga `.if t .ds ga \(ga.if t .tr *\(**.TH csh 1.SH Namecsh \- C shell Command Interpreter.SH Syntax.B csh[\fB\-cefinstvVxX\fR\|] [\|\fIarg...\fR\|].SH Description.NXR "C shell" "See csh command interpreter".NXR "csh command interpreter"The.PN cshcommand is a command language interpreter that consists of a history mechanism, job control facilities, and a C-like syntax.  While this command has a set of .I built-infunctions that it performs directly, the command line interpreteralso reads and translates commands that invokes other programs.Additionally, you can create shell scripts which the.PN cshcommand can interpret.  Shell scripts are files which contain executableinstructions..PPThe percent sign (%) represents the system prompt.  It indicatesthat you can begin entering commands to the system.  Each command line that you type is read and broken into words.  This sequence of words is placed on a command history list andthen parsed.  When the entire command line has executed, thepercent sign reappears and you can enter another command.  See the History Substitution and Jobs sections for more information..PPTo use the.PN cshcommand's full job control facilities, you must invoke the ttydriver described in .MS tty 4 .This driver allows generation of interrupt characters from thekeyboard which stop execution of a job.  For details on settingoptions in the tty driver, see.MS stty 1 ..PPNote that your environment setup is controlled by commands in thehome directory of your .cshrc file.  The .PN cshcommand executes these commands when you enter the system.  Additionally,if this is a login shell, the Shell also executes the commands inyour .login file.  These files usually contain your options for thetty driver and .MS tset 1 ,(terminal settings).When a login shell session ends, commands are executed from the .logoutfile in your home directory..SH Lexical Structure.NXR "csh command interpreter" "lexical structure"The shell splits input lines into words at blanks and tabs with thefollowing exceptions:.IP \(bu 5ampersand (&).IP \(bu 5bar ( | ).IP \(bu 5semicolon ( ; ).IP \(bu 5Left (<) and right (>) angle brackets.IP \(bu 5Left (() and right ()) parenthesis.PPThe previous metacharacters form separate words.  If doubled as follows,these metacharacters form single words:.IP \(bu 5Doubled ampersand (&&).IP \(bu 5Double bars (||).IP \(bu 5Double left (<<) and right (>>) brackets.IP \(bu 5Backslash (\e).IP \(bu 5Single (\` \`) and double (" ") quotation marks..PPMetacharacters can be a part of other words.  Additionally, if you donot want a metacharacter to be interpreted as such by the system, you canprecede it with a backslash e (\\e).  A new line that is preceded by ais equivalent to a blank..PPStrings enclosed in single quotes (\` \`) or strings enclosedin double quotes (" ") form parts of a word.  Metacharacters in thesestrings, including blanks and tabs, do not form separate words.  Thisis described in more detail later.  Within single quotes or doublequotes, a new line preceded by a backslash (\e) gives a true new linecharacter..PPWhen the shell's input is not a terminal,the pound sign (#) introduces a comment which continues to the end of theinput line.It is prevented this special meaning when preceded by a backslash (\e)and single or double quotation marks..SH Commands.NXR "csh command interpreter" "command definition"A command is a word or sequence of words that directs the systemto perform a certain function.  You can separate commands witha bar ( | ) which forms a pipeline.  The output that results fromeach command in the pipeline is connected to the input of thenext.  For example, in the following pipeline, a file is copiedand the output is piped to standard output (the screen):.EX% cp /example/dir/test . | more.EEYou can form and execute several pipelines by separating each pipeline with a semicolon (;).  You can also force a command tocomplete execution in the background by typing an ampersand (&) atthe end of the command line..PPYou can form a simple command (which may be a component of apipeline and so on) by placing any of the above in parenthesis(()).  As in the C language, you can also separate pipelineswith a double bar (||) or double ampersands (&&).  The doublebar tells the command interpreter to execute the secondcommand only if the first command fails.  The double ampersandstells the command interpreter to execute the second command ifthe first command is successful..SH Jobs.NXR "csh command interpreter" "running jobs"The Shell associates each command or pipeline with a.I jobindex.  By typing.B jobsat the system prompt, a table of the current jobs is printed onyour screen.  Each job listed has a small integer numberassociated with it.  For example, if you force a job into the background usingan ampersand (&), the shell displays the job number and process id of that job as follows:.EX[1] 1234.EE.PPIn the previous example, the job number is 1 indicating that thisis a background job and the process id is 1234..PPIf you are running a job in the foreground, you can suspendexecution of that job by typing a CTRL/Z.  The Shell then indicatesthat the job has been stopped and the system prompt reappears. If youtype jobs at the prompt, the display indicates that a job hasbeen stopped.  You can either enter another command at the prompt or you can manipulate the state of the job you suspended as follows:.IP \(bu 5Place the job in background by using the .B bgcommand..IP \(bu 5Continue to execute the job by placing it in the foreground using the.B fgcommand..PPA CTRL/Z takes effect immediately and is like an interrupt.  For example,pending output and unread output are discarded when the CTRL/Z is issued.You can also type a CTRL/Y which does not generate a stop signal untila program attempts to perform a.MS read 2operation..PPIf a job that is being run in the background attempts to read fromthe terminal, it will stop.  Background jobs can produce output.  Youcan prevent background jobs from producing output by issuing thefollowing command:.EXstty tostop.EE.PPThere are several ways to refer to jobs in the shell.  For example, to bring job number 1 into the foreground, type %1 or fg %1.  Similarly, %1 & returns job 1 to the background.  If a job does not have an ambiguous prefix, you canrestart a job by it's prefix.  For example, %ex would restart asuspended.PN exjob, if it is the only suspended .PN exjob.  You use also use %?\fIstring\fR which specifies a job whose commandline contains.I string. Again, .I string cannot be an ambiguous name. .PPThe Shell tracks the current and previous jobs.  For example,in output displays of jobs, the current job is marked witha plus sign (+) and the previous job is marked with a minussign (-).  Hence, you can type %+ for the current job and %-for the previous job.  You can also specify %% which specifiesthe current job..SH Status Reporting.NXR "csh command interpreter" "reporting job status"The Shell performs status reporting when the process statechanges.  For example, if a job becomes blocked and furtherprocessing is not possible, the Shell informs you just beforeit prints a prompt.  If, however, you set the Shell variable.I notify,the Shell provides you with immediate status of background jobs.As opposed to notifying you of all changes in background jobs,the Shell command .I notifycan mark a single process so that only its status change is reported.To mark a single file, type notify after starting a backgroundjob.  By default, only the current process is marked..PPIf you try to exit from the Shell while jobs are stopped, thefollowing warning appears:.EXYou have stopped jobs..EE.PPYou can use the .B jobscommand to view the stopped jobs. If you immediately try toexit again, the Shell does not provide a second warning andsuspended jobs are terminated..SH SubstitutionsThe various transformations the shell performs on the input is nowdescribed in the order in which they occur..SH History Substitutions.NXR "csh command interpreter" "repeating commands"History substitutions allow you to use words from previously typedcommands as portions of new commands.  This enables you to repeatcommands, arguments, or fix spelling mistakes from the previous command..PPAn exclamation point (!) marks the beginning of a history substitution.  It can appear anywhere in the input stream (includingthe beginning) as long as it is not nested.  An input line thatcontains history substitution is echoed to the screen before it isexecuted..PPThe exclamation point (!) may be preceded by a backslash (\e) ifyou want to escape its special meaning.  If an exclamation pointis followed by a blank, tab, new line, equal sign (=), or leftparenthesis ((), it is passed unchanged..PPAny command line that is typed at the terminal is saved on thehistory list.  You can increase or decrease the size of yourhistory list using the.I historyvariable; the previous command is always retained regardless of its value.Commands are numbered sequentially from 1. To display the historyon your terminal, type history at the prompt as follows:.EX% history.EE.PPThis command lists the commands that were previously typed.  For example:.EX1  write michael2  ex write.c3  cat oldwrite.c4  diff*write.c.EE.PPThe commands are shown with their event numbers.  Although it is not usuallynecessary to use event numbers, you can reinvoke any command by combiningthe exclamation point (!) with any event number.  For example, if you arereferencing the previous history list, !4 reinvokes the command line diff*write.c.  You can also reinvoke a command without the event numberas long as it is not ambiguous.  For example, !c invokes event 3 or !wri invokes event 1.  The line !?mic? also refers to event 1.  If you type!!, the last command entered in reinvoked..PPTo select words from an event, follow the event specification with a colon (:) and a designator for the desired words.The words of a input line are numbered from 0, the first (usually command) word being 0, the second word (first argument)being 1, and so forth.The basic word designators are:.PP.DT.nf	0	first (command) word	\fIn\fR	\fIn\fR\|'th argument	!	first argument,  that is `1'	$	last argument	%	word matched by (immediately preceding) ?\fIs\fR\|? search	\fIx\fR\|\-\fIy\fR	range of words	\-\fIy\fR	abbreviates `0\-\fIy\fR\|'	*	abbreviates `!-$', or nothing if only 1 word in event	\fIx\fR\|*	abbreviates `\fIx\fR\|\-$'	\fIx\fR\|\-	like `\fIx\fR\|*' but omitting word `$'.fi.PPThe colon (:) separating the event specification from the word designatorcan be omitted if the argument selector begins with a `!', `$', `*'`\-' or `%'.After the optional word designator can beplaced a sequence of modifiers, each preceded by a colon (:).The following modifiers are defined:.ta .5i 1.2i.PP.nf	h	Remove a trailing pathname component, leaving the head.	r	Remove a trailing `.xxx' component, leaving the root name.	e	Remove all but the extension `.xxx' part.	s/\fIl\fR\|/\fIr\fR\|/	Substitute \fIl\fR for \fIr\fR	t	Remove all leading pathname components, leaving the tail.	&	Repeat the previous substitution.	g	Apply the change globally, prefixing the above, for example, `g&'.	p	Print the new command but do not execute it.	q	Quote the substituted words, preventing further substitutions.	x	Like q, but break into words at blanks, tabs and new lines..fi.PPUnless preceded by a `g' the modification is applied only to the firstmodifiable word.  With substitutions, it is an error for no word to beapplicable..PPThe left hand side of substitutions are not regular expressions in the senseof the editors, but rather strings.Any character may be used as the delimiter in place of `/';a `\e' quotes the delimiter into the.IR l ""and.IR r ""strings.The character `&' in the right hand side is replaced by the text fromthe left.A `\e' quotes `&' also.A null.IR l ""uses the previous string either from a.IR l ""or from acontextual scan string.IR s ""in `!?\fIs\fR\|?'.The trailing delimiter in the substitution may be omitted if a new linefollows immediately as may the trailing `?' in a contextual scan..PPA special abbreviation of a history reference occurs when the firstnon-blank character of an input line is a circumflex (^).This is equivalent to `!!:s/' providing a convenient shorthand for substitutions on the text of the previous line.Thus `^lb^lib^' fixes the spelling of lb in the previous command.Finally, a history substitution may be surrounded with `{' and `}'if necessary to insulate it from the characters which follow.Thus, after `ls \-ld ~paul' we might do `!{l}a' to do `ls \-ld ~paula',while `!la' would look for a command starting `la'..PP.if n .ul\fBQuotations\ with\ \'\ and\ "\fR.NXR "csh command interpreter" "quoted strings and".PPThe quotation of strings by `\'' and `"' can be usedto prevent all or some of the remaining substitutions.Strings enclosed in `\'' are prevented any further interpretation.Strings enclosed in `"' may be expanded as described below..PPIn both cases the resulting text becomes (all or part of) a single word;only in one special case (see.I "Command Substitution"below) does a `"' quoted string yield parts of more than one word;`\'' quoted strings never do..SH Alias Substitution.NXR "csh command interpreter" "substituting an alias"The shell maintains a list of aliases that can be established, displayed,and modified by the.I aliasand.I unaliascommands. .PPAfter the shell scans a command line, it parses the line intodistinct commands. Then, the shell checks the first word of eachcommand, in left-to-right order, to determine if the command linecontains an alias. When the shell finds an alias, it substitutes thedefinition of the alias for the alias in the command line. The shellreads the definition of the alias using the history mechanism andtreats the definition as if it was the previous input line.If the alias definition makes no reference to the history list, theshell leaves the command's argument unchanged..PPFor example, the following command creates an alias called ``ls:''.EX% alias ls \'ls \-l\'.EEAfter you issue this .I aliascommand, you receive information about files such as their mode, number of links,owner, and so on when you use the ls alias.For example, the following shows the output from the lsalias created in the preceeding example:.EX% ls \/usr\/smith\/text_file-rw-r--r--  1 smith          21 Mar 12 11:53 text_file.EEYou can also create aliases that allow you to supply arguments on thecommand line and arguments in the alias definition, as shownin the following example:.EX% alias lookup \'grep \e!^ /etc/passwd\' .EEYou must specify ``\\'' before the \*Q!\*U to prevent the substitutionfrom occurring in the .I alias command. The following shows the output from the lookup alias:.EX% lookup smithsmith:2vruqPosbG/bE:1321:10::\/usr\/smith:\/bin\/csh.EEThe lookup alias finds and displays user Smith's entry in the.PN /etc/passwd file..PPYou can specify an alias within an alias definition. After the shellfinds an alias and substitutes its definition, it searches again for aliases. The shell flags definitions that begin with the same word as thealias to prevent infinite loops. Other loops are detected and cause anerror. .PPYou can use parser metasyntax in an .I aliascommand. For example, the following is a valid command that creates theprint alias:.EX % alias print \'pr \e!* \||\| lpr\' .EEThe print alias pipes output from the.PN prcommand to the.PN lprcommand..SH Variable Substitution.NXR "csh command interpreter" "variable substitution"The shell maintains a set of variables, each of which has as value a listof zero or more words.Some of these variables are set by the shell or referred to by it.For instance, the.I argvvariable is an image of the shell's argument list, and words of thisvariable's value are referred to in special ways..PPThe values of variables may be displayed and changed by using the.I setand.I unsetcommands.Of the variables referred to by the shell a number are toggles;the shell does not care what their value is,only whether they are set or not.For instance, the.I verbosevariable is a toggle which causes command input to be echoed.The setting of this variable results from the.B \-v

⌨️ 快捷键说明

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