📄 csh.4
字号:
.\" Copyright (c) 1980, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)csh.4 8.1 (Berkeley) 6/8/93.\".nr H1 3.NHOther, less commonly used, shell features.NH 2Loops at the terminal; variables as vectors.PPIt is occasionally useful to use the.I foreachcontrol structure at the terminal to aid in performing a numberof similar commands.For instance, there were at one point three shells in use on the Cory \s-2UNIX\s0system at Cory Hall,`/bin/sh',`/bin/nsh',and`/bin/csh'.To count the number of persons using each shell one could have issuedthe commands.DS% grep \-c csh$ /etc/passwd27% grep \-c nsh$ /etc/passwd128% grep \-c \-v sh$ /etc/passwd430%.DESince these commands are very similar we can use.I foreachto do this more easily..DS% foreach i (\'sh$\' \'csh$\' \'\-v sh$\')? grep \-c $i /etc/passwd? end27128430%.DENote here that the shell prompts forinput with `? ' when reading the body of the loop..PPVery useful with loops are variables which contain lists of filenamesor other words.You can, for example, do.DS% set a=(\`ls\`)% echo $acsh.n csh.rm% lscsh.ncsh.rm% echo $#a2%.DEThe.I setcommand here gave the variable.I aa list of all the filenames in the current directory as value.We can then iterate over these names to perform any chosen function..PPThe output of a command within `\`' characters is converted bythe shell to a list of words.You can also place the `\`' quoted string within `"' charactersto take each (non-empty) line as a component of the variable;preventing the lines from being split into words at blanks and tabs.A modifier `:x' exists which can be used later to expand each componentof the variable into another variable splitting it into separate wordsat embedded blanks and tabs..NH 2Braces { ... } in argument expansion.PPAnother form of filename expansion, alludedto before involves the characters `{' and `}'.These characters specify that the contained strings, separated by `,'are to be consecutively substituted into the containing charactersand the results expanded left to right.Thus.DSA{str1,str2,...strn}B.DEexpands to.DSAstr1B Astr2B ... AstrnB.DEThis expansion occurs before the other filename expansions, and maybe applied recursively (i.e. nested).The results of each expanded string are sorted separately, leftto right order being preserved.The resulting filenames are not required to exist if no other expansionmechanisms are used.This means that this mechanism can be used to generate arguments which arenot filenames, but which have common parts..PPA typical use of this would be.DSmkdir ~/{hdrs,retrofit,csh}.DEto make subdirectories `hdrs', `retrofit' and `csh'in your home directory.This mechanism is most useful when the common prefix is longerthan in this example, i.e..DSchown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}.DE.NH 2Command substitution.PPA command enclosed in `\`' characters is replaced, just beforefilenames are expanded, by the output from that command.Thus it is possible to do.DSset pwd=\`pwd\`.DEto save the current directory in the variable.I pwdor to do.DSex \`grep \-l TRACE *.c\`.DEto run the editor.I exsupplying as arguments those files whose names end in `.c'which have the string `TRACE' in them.*.FS*Command expansion also occurs in input redirected with `<<'and within `"' quotations.Refer to the shell manual section for full details..FE.NH 2Other details not covered here.PPIn particular circumstances it may be necessary to know the exactnature and order of different substitutions performed by the shell.The exact meaning of certain combinations of quotations is alsooccasionally important.These are detailed fully in its manual section..PPThe shell has a number of command line option flags mostly of usein writing \s-2UNIX\s0 programs,and debugging shell scripts.See the csh(1) manual section for a list of these options..bp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -