csh.1
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 1 代码 · 共 2,332 行 · 第 1/5 页
1
2,332 行
command 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 subsequent 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.B alwaysoccurs, and within `\''s where it.B neveroccurs.Strings quoted by `\*(ga' are interpreted later (see.I "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 file name 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 file name substitution..PPThe following metasequences are provided for introducing variable values intothe shell input.Except as noted, it is an error to reference a variable which is not set..HP 5$name.br.ns.HP 5${name}.brAre replaced by the words of the value of variable.I name,each separated by a blank.Braces insulate.I namefrom following characters which 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..brIf.I nameis not a shell variable, but is set in the environment, thenthat value is returned (but \fB:\fR modifiers and the other formsgiven below are not available in this case)..HP 5$name[selector].br.ns.HP 5${name[selector]}.brMay be used to select only some of the words from the value of.I 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 member 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..HP 5$#name.br.ns.HP 5${#name}.brGives the number of words in the variable.This is useful for later use in a `[selector]'..HP 5$0.brSubstitutes the name of the file from which command input is being read.An error occurs if the name is not known..HP 5$number.br.ns.HP 5${number}.brEquivalent to `$argv[number]'..HP 5$*.brEquivalent to `$argv[*]'..PPThe modifiers `: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..NTThe current implementation allows only one colon (:) modifier on each `$' expansion.".NEThe following substitutions may not be modified with colon (:) modifiers..HP 5$?name.br.ns.HP 5${?name}.brSubstitutes the string `1' if name is set, `0' if it is not..HP 5$?0.brSubstitutes `1' if the current input file name is known, `0' if it is not..HP 5$$.brSubstitute the (decimal) process number of the (parent) shell..HP 5$<.brSubstitutes a line from the standardinput, with no further interpretation thereafter. It can be usedto read from the keyboard in a shell script..SH Command And File Name Substitution.NXR "csh command interpreter" "variable substitution"The remaining substitutions, command and file name substitution,are applied selectively to the arguments of built-in commands.This means that portions of expressions which are not evaluated arenot subjected to these expansions.For commands which 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..SH Command Substitution.NXR "csh command interpreter" "command substitution"Command substitution is indicated by a command enclosed in `\*(ga'.The output from such a command is normally broken into separate wordsat blanks, tabs and new lines, with null words being discarded,this text then replacing the original string.Within `"'s, only new lines force new words; blanks and tabs are preserved..PPIn any case, the single final new line 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..SH File Name Substitution.NXR "csh command interpreter" "file name substitution"If a word contains any of the characters `*', `?', `[' or `{'or begins with the character `~', then that word is a candidate forfile name substitution, also known as `globbing'.This word is then regarded as a pattern, and replaced with an alphabeticallysorted list of file names which match the pattern.In a list of words specifying file name 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 file names, the character `.' at the beginning of a file nameor 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 `[...]' matches any one of the characters enclosed.Within `[...]',a pair of characters separated by `\-' matches any character lexically betweenthe two..PPThe character `~' at the beginning of a file name is used to refer to homedirectories.Standing alone, that is `~', itexpands to the invokers home directory as reflectedin the value of the variable.I home.When followed by a name consisting of letters, digits and `\-' charactersthe 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 appears not 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'whether or not these files exist without any 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 matching `*box'.)As a special case `{', `}' and `{}' are passed undisturbed..SH Input/output.NXR "csh command interpreter" "command input/output"The standard input and standard output of a command may be redirectedwith the following syntax:.HP 5< name.brOpen file.I name(which is first variable, command and file name expanded) as the standardinput..HP 5<< word.brRead the shell input up to a line which is identical to.I word..I Wordis not subjected to variable, file name or command substitution,and each input line is compared to.I wordbefore any substitutions are done on this input line.Unless a quoting `\e', `"', `\*(aa' or `\*(ga' appears in.I wordvariable and command substitution is performed on the intervening lines,allowing `\e' to quote `$', `\e' and `\*(ga'.Commands which are substituted have all blanks, tabs, and new linespreserved, except for the final new line which is dropped.The resultant text is placed in an anonymous temporary file whichis given to the command as standard input..HP 5> name.br.ns.HP 5>! name.br.ns.HP 5>& name.br.ns.HP 5>&! name.brThe file.I nameis used as standard output.If the file does not exist then it is created;if the file exists, it is truncated, its previous contents being lost..IPIf the variable.I noclobberis set, then the file must not exist or be a character special file (for example,a terminal or `/dev/null') or an error results.This helps prevent accidental destruction of files.In this case the `!' forms can be used and suppress this check..IPThe forms involving `&' route the diagnostic output into the specifiedfile as well as the standard output..I Nameis expanded in the same way as `<' input file names are..HP 5>> name.br.ns.HP 5>>& name.br.ns.HP 5>>! name.br.ns.HP 5>>&! name.brUses file.I nameas standard output like `>' but places output at the end of the file.If the variable.I noclobberis set, then it is an error for the file not to exist unlessone of the `!' forms is given.Otherwise similar to `>'..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; ratherthey 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.B notmodified to be the empty file `/dev/null'; rather 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.B Jobsabove.).PPDiagnostic output may be directed through a pipe with the standard output.Simply use the form `|\|&' rather than just `|'..SH Expressions.NXR "csh command interpreter" "expressions"A number of the built-in commands (to be described subsequently)take expressions, in which the operators are similar to those of C, withthe same precedence.These expressions appear in the.I @,.I exit,.I if,and.I whilecommands.The following operators are available:.DT.PP |\|\|| && | ! & == != =~ !~ <= >= < > << >> + \- * / % ! ~ ( ).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.I pattern(containing, for example, `*'s, `?'s and instances of `[...]')against which the left hand operand is matched. This reduces theneed for use of the.I switchstatement in shell scripts when all that is really needed is pattern matching..PPStrings which 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 whichare 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 `\-\fIl\fR name' where.I lis one of:.PP.DT.nf r read access w write access x execute access e existence o ownership z zero size f plain file d directory.fi.PPThe specified name is command and file name 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, that is `0'.Command executions succeed, returning true, that is `1',if the command exits with status 0, otherwise they fail, returningfalse, that is `0'.If more detailed status information is required then the commandshould be executed outside of an expression and the variable.I statusexamined..SH Control Flow.NXR "csh command interpreter" "flow of control"The shell contains a number of commands which 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, due to the implementation, restrict the placement of someof the commands..PPThe.I foreach,.I switch,and.I whilestatements, as well as the.I if\-then\-elseform of the.I 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.).SH Built-in Commands.NXR "csh command interpreter" "built-in commands"Built-in commands are executed within the shell.If a built-in command occurs as any component of a pipelineexcept the last then it is executed in a subshell..HP 5.B alias.br.ns.HP 5.BR alias " name".br.ns.HP 5.BR alias " name wordlist".NXR "alias command (csh)".brThe first form prints all aliases.The second form prints the alias for name.The final form assigns the specified.I wordlistas the alias of .I name;.I wordlistis command and file name substituted..I Nameis not allowed to be.I aliasor.I unalias..HP 5.B alloc.NXR "alloc command (csh)".brShows the amount of dynamic core in use, broken down into used andfree core, and address of the last location in the heap.With an argument shows each used and free block on the internal dynamicmemory chain indicating its address, size, and whether it is used or free.This is a debugging command and may not work in production versions of theshell; it requires a modified version of the system memory allocator..HP 5.B bg.NXR "bg command (csh)".br.ns.HP 5\fBbg\ %\fRjob\ ....brPuts the current or specified jobs into the background, continuing themif they were stopped..HP 5.B break.NXR "break command (csh)".brCauses execution to resume after the.I endof the nearest enclosing.I foreach
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?