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

📄 csh.1

📁 早期freebsd实现
💻 1
📖 第 1 页 / 共 5 页
字号:
.Dl % set fignore = (.o .out).Ppthen typing.Pp.Dl % vi x<escape>.Ppwould result in the completion to.Pp.Dl % vi xmpl.c.Ppignoring the files "xmpl.o" and "xmpl.out".However, if the only completion possible requires not ignoring thesesuffixes, then they are not ignored.  In addition,.Ar fignoredoes not affect the listing of file names by control-D.  All filesare listed regardless of their suffixes..Ss SubstitutionsWe now describe the various transformations the shell performs on theinput in the order in which they occur..Ss History substitutionsHistory substitutions place words from previous command input as portionsof new commands, making it easy to repeat commands, repeat argumentsof a previous command in the current command, or fix spelling mistakesin the previous command with little typing and a high degree of confidence.History substitutions begin with the character `!' and may begin.Ar anywherein the input stream (with the proviso that they.Nm "do not"nest.)This `!' may be preceded by a `\e' to prevent its special meaning; forconvenience, an `!' is passed unchanged when it is followed by a blank,tab, newline, `=' or `('.(History substitutions also occur when an input line begins with `\*(ua'.This special abbreviation will be described later.)Any input line that contains history substitution is echoed on the terminalbefore it is executed as it could have been typed without history substitution..PpCommands input from the terminal that consist of one or more wordsare saved on the history list.The history substitutions reintroduce sequences of words from thesesaved commands into the input stream.The size of the history list is controlled by the.Ar historyvariable; the previous command is always retained,regardless of the value of the history variable.Commands are numbered sequentially from 1..PpFor definiteness, consider the following output from the.Ar historycommand:.Bd -literal -offset indent\09  write michael10  ex write.c11  cat oldwrite.c12  diff *write.c.Ed.PpThe commands are shown with their event numbers.It is not usually necessary to use event numbers, but the current eventnumber can be made part of the.Ar promptby placing an `!' in the prompt string..PpWith the current event 13 we can refer to previous events by eventnumber `!11', relatively as in `!\-2' (referring to the same event),by a prefix of a command wordas in `!d' for event 12 or `!wri' for event 9, or by a string contained ina word in the command as in `!?mic?' also referring to event 9.These forms, without further change, simply reintroduce the wordsof the specified events, each separated by a single blank.As a special case, `!!' refers to the previous command; thus `!!'alone is a.Ar redo ..PpTo select words from an event we can follow the event specification bya `:' and a designator for the desired words.The words of an input line are numbered from 0,the first (usually command) word being 0, the second word (first argument)being 1, etc.The basic word designators are:.Pp.Bl -tag -width Ds -compact -offset indent.It \&0first (command) word.It Ar n.Ar n Ns 'thargument.It \*(uafirst argument,  i.e., `1'.It $last argument.It %word matched by (immediately preceding).No \&? Ns Ar s Ns \&?search.It Ar \&x\-yrange of words.It Ar \&\-yabbreviates.Ar `\&0\-y\'.It *abbreviates `\*(ua\-$', or nothing if only 1 word in event.It Ar x*abbreviates.Ar `x\-$\'.It Ar x\-like.Ar `x*\'but omitting word `$'.El.PpThe `:' separating the event specification from the word designatorcan be omitted if the argument selector begins with a `\*(ua', `$', `*'`\-' or `%'.After the optional word designator can beplaced a sequence of modifiers, each preceded by a `:'.The following modifiers are defined:.Pp.Bl -tag -width Ds -compact -offset indent.It hRemove a trailing pathname component, leaving the head..It rRemove a trailing `.xxx' component, leaving the root name..It eRemove all but the extension `.xxx' part..It s Ns Ar /l/r/Substitute.Ar lfor.Ar r.It tRemove all leading pathname components, leaving the tail..It \&&Repeat the previous substitution..It gApply the change once on each word, prefixing the above, e.g., `g&'..It aApply the change as many times as possible on a single word, prefixingthe above. It can be used together with `g' to apply a substitution globally..It pPrint the new command line but do not execute it..It qQuote the substituted words, preventing further substitutions..It xLike q, but break into words at blanks, tabs and newlines..El.PpUnless preceded by a `g' the change 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 instead strings.Any character may be used as the delimiter in place of `/';a `\e' quotes the delimiter into the.Ar l  " "and.Ar r  " "strings.The character `&' in the right hand side is replaced by the text fromthe left.A `\e' also quotes `&'.A null.Ar l(`//')uses the previous string either from an.Ar lor from acontextual scan string.Ar sin.No \&`!? Ns Ar s Ns \e?' .The trailing delimiter in the substitution may be omitted if a newlinefollows immediately as may the trailing `?' in a contextual scan..PpA history reference may be given without an event specification, e.g., `!$'.Here, the reference is to the previous command unless a previoushistory reference occurred on the same line in which case this form repeatsthe previous reference.Thus `!?foo?\*(ua !$' gives the first and last argumentsfrom the command matching `?foo?'..PpA special abbreviation of a history reference occurs when the firstnon-blank character of an input line is a `\*(ua'.This is equivalent to `!:s\*(ua' providing a convenient shorthand for substitutionson the text of the previous line.Thus `\*(ualb\*(ualib' fixes the spelling of`lib'in the previous command.Finally, a history substitution may be surrounded with `{' and `}'if necessary to insulate it from the characters that follow.Thus, after `ls \-ld ~paul' we might do `!{l}a' to do `ls \-ld ~paula',while `!la' would look for a command starting with `la'..Pp.Ss Quotations with \' and \&"The 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.Em Command Substitutionbelow) does a `"' quoted string yield parts of more than one word;`\'' quoted strings never do..Ss Alias substitutionThe shell maintains a list of aliases that can be established, displayedand modified by the.Ar aliasand.Ar unaliascommands.After a command line is scanned, it is parsed into distinct commands andthe first word of each command, left-to-right, is checked to see if ithas an alias.If it does, then the text that is the alias for that command is rereadwith the history mechanism availableas though that command were the previous input line.The resulting words replace thecommand and argument list.If no reference is made to the history list, then the argument list isleft unchanged..PpThus if the alias for `ls' is `ls \-l' the command `ls /usr' would map to`ls \-l /usr', the argument list here being undisturbed.Similarly if the alias for `lookup' was `grep !\*(ua /etc/passwd' then`lookup bill' would map to `grep bill /etc/passwd'..PpIf an alias is found, the word transformation of the input textis performed and the aliasing process begins again on the reformed input line.Looping is prevented if the first word of the new text is the same as the oldby flagging it to prevent further aliasing.Other loops are detected and cause an error..PpNote that the mechanism allows aliases to introduce parser metasyntax.Thus, we can `alias print \'pr \e!* \&| lpr\'' to make a command that.Ar pr Ns 'sits arguments to the line printer..Ss Variable substitutionThe 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.Ar 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.Ar setand.Ar 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.Ar verbosevariable is a toggle that causes command input to be echoed.The setting of this variable results from the.Fl vcommand line option..PpOther operations treat variables numerically.The `@' command permits numeric calculations to be performed and the resultassigned to a variable.Variable values are, however, always represented as (zero or more) strings.For the purposes of numeric operations, the null string is considered to bezero, and the second and additional words of multiword values are ignored..PpAfter the input line is aliased and parsed, and before each commandis executed, variable substitutionis performed keyed by `$' characters.This expansion can be prevented by preceding the `$' with a `\e' exceptwithin `"'s where it.Em alwaysoccurs, and within `\''s where it.Em neveroccurs.Strings quoted by `\*(ga' are interpreted later (see.Nm "Command substitution"below) so `$' substitution does not occur there until later, if at all.A `$' is passed unchanged if followed by a blank, tab, or end-of-line..PpInput/output redirections are recognized before variable expansion,and are variable expanded separately.Otherwise, the command name and entire argument list are expanded together.It is thus possible for the first (command) word (to this point) to generatemore than one word, the first of which becomes the command name,and the rest of which become arguments..PpUnless enclosed in `"' or given the `:q' modifier the results of variablesubstitution may eventually be command and filename substituted.Within `"', a variable whose value consists of multiple words expands to a(portion of) a single word, with the words of the variables valueseparated by blanks.When the `:q' modifier is applied to a substitutionthe variable will expand to multiple words with each word separatedby a blank and quoted to prevent later command or filename substitution..PpThe following metasequences are provided for introducing variable values intothe shell input.Except as noted, it is an error to reference a variable that is not set..Pp.Bl -tag -width Ds -compact -offset indent.It $name.It ${name}Are replaced by the words of the value of variable.Ar name ,each separated by a blank.Braces insulate.Ar namefrom following characters that would otherwise be part of it.Shell variables have names consisting of up to 20 letters and digitsstarting with a letter.  The underscore character is considered a letter.If.Ar nameis not a shell variable, but is set in the environment, thenthat value is returned (but.Nm :modifiers and the other formsgiven below are not available here)..It $name Ns Op selector.It ${name Ns [ selector ] }May be used to select only some of the words from the value of.Ar name .The selector is subjected to `$' substitution and may consist of a singlenumber or two numbers separated by a `\-'.The first word of a variables value is numbered `1'.If the first number of a range is omitted it defaults to `1'.If the last number of a range is omitted it defaults to `$#name'.The selector `*' selects all words.It is not an error for a range to be empty if the second argument is omittedor in range..It $#name.It ${#name}Gives the number of words in the variable.This is useful for later use in a`$argv[selector]'..It $0Substitutes the name of the file from which command input is being read.An error occurs if the name is not known..It $number.It ${number}Equivalent to`$argv[number]'..It $*Equivalent to`$argv[*]'.The modifiers `:e', `:h', `:t', `:r', `:q' and `:x' may be applied tothe substitutions above as may `:gh', `:gt' and `:gr'.If braces `{' '}' appear in the command form then the modifiersmust appear within the braces.The current implementation allows only one `:' modifier on each `$' expansion..El.PpThe following substitutions may not be modified with `:' modifiers..Bl -tag -width Ds -compact -offset indent.It $?name.It ${?name}Substitutes the string `1' if name is set, `0' if it is not..It $?0Substitutes `1' if the current input filename is known, `0' if it is not..It \&$\&$\&Substitute the (decimal) process number of the (parent) shell..It $!Substitute the (decimal) process number of the last background processstarted by this shell..It $<Substitutes a line from the standardinput, with no further interpretation.It can be used to read from the keyboard in a shell script..El.Ss Command and filename substitutionThe remaining substitutions, command and filename substitution,are applied selectively to the arguments of builtin commands.By selectively, we mean that portions of expressions which arenot evaluated are not subjected to these expansions.For commands that are not internal to the shell, the commandname is substituted separately from the argument list.This occurs very late,after input-output redirection is performed, and in a childof the main shell..Ss Command substitutionCommand substitution is shown by a command enclosed in `\*(ga'.The output from such a command is normally broken into separate wordsat blanks, tabs and newlines, with null words being discarded;this text then replaces the original string.Within `"'s, only newlines force new words; blanks and tabs are preserved..PpIn any case, the single final newline does not force a new word.Note that it is thus possible for a command substitution to yieldonly part of a word, even if the command outputs a complete line..Ss Filename substitutionIf a word contains any of the characters `*', `?', `[' or `{'or begins with the character `~', then that word is a candidate forfilename substitution, also known as `globbing'.This word is then regarded as a pattern, and replaced with an alphabeticallysorted list of file names that match the pattern.In a list of words specifying filename substitution it is an error forno pattern to match an existing file name, but it is not requiredfor each pattern to match.Only the metacharacters `*', `?' and `[' imply pattern matching,the characters `~' and `{' being more akin to abbreviations..PpIn matching filenames, the character `.' at the beginning of a filenameor immediately following a `/', as well as the character `/' mustbe matched explicitly.The character `*' matches any string of characters, including the nullstring.The character `?' matches any single character.The sequence.Sq Op ...matches any one of the characters enclosed.Within.Sq Op ... ,a pair of characters separated by `\-' matches any character lexically betweenthe two (inclusive)..PpThe character `~' at the beginning of a filename refers to homedirectories.

⌨️ 快捷键说明

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