1 .\" $NetBSD: csh.4,v 1.3 1995/03/21 09:03:39 cgd Exp $
3 .\" Copyright (c) 1980, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)csh.4 8.1 (Berkeley) 6/8/93
34 Other, less commonly used, shell features
36 Loops at the terminal; variables as vectors
38 It is occasionally useful to use the
40 control structure at the terminal to aid in performing a number
42 For instance, there were at one point three shells in use on the Cory \s-2UNIX\s0
48 To count the number of persons using each shell one could have issued
51 % grep \-c csh$ /etc/passwd
53 % grep \-c nsh$ /etc/passwd
55 % grep \-c \-v sh$ /etc/passwd
59 Since these commands are very similar we can use
61 to do this more easily.
63 % foreach i (\'sh$\' \'csh$\' \'\-v sh$\')
64 ? grep \-c $i /etc/passwd
71 Note here that the shell prompts for
72 input with `? ' when reading the body of the loop.
74 Very useful with loops are variables which contain lists of filenames
76 You can, for example, do
90 command here gave the variable
92 a list of all the filenames in the current directory as value.
93 We can then iterate over these names to perform any chosen function.
95 The output of a command within `\`' characters is converted by
96 the shell to a list of words.
97 You can also place the `\`' quoted string within `"' characters
98 to take each (non-empty) line as a component of the variable;
99 preventing the lines from being split into words at blanks and tabs.
100 A modifier `:x' exists which can be used later to expand each component
101 of the variable into another variable splitting it into separate words
102 at embedded blanks and tabs.
104 Braces { ... } in argument expansion
106 Another form of filename expansion, alluded
107 to before involves the characters `{' and `}'.
108 These characters specify that the contained strings, separated by `,'
109 are to be consecutively substituted into the containing characters
110 and the results expanded left to right.
113 A{str1,str2,...strn}B
117 Astr1B Astr2B ... AstrnB
119 This expansion occurs before the other filename expansions, and may
120 be applied recursively (i.e. nested).
121 The results of each expanded string are sorted separately, left
122 to right order being preserved.
123 The resulting filenames are not required to exist if no other expansion
125 This means that this mechanism can be used to generate arguments which are
126 not filenames, but which have common parts.
128 A typical use of this would be
130 mkdir ~/{hdrs,retrofit,csh}
132 to make subdirectories `hdrs', `retrofit' and `csh'
133 in your home directory.
134 This mechanism is most useful when the common prefix is longer
135 than in this example, i.e.
137 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
142 A command enclosed in `\`' characters is replaced, just before
143 filenames are expanded, by the output from that command.
144 Thus it is possible to do
148 to save the current directory in the variable
152 ex \`grep \-l TRACE *.c\`
156 supplying as arguments those files whose names end in `.c'
157 which have the string `TRACE' in them.*
159 *Command expansion also occurs in input redirected with `<<'
160 and within `"' quotations.
161 Refer to the shell manual section for full details.
164 Other details not covered here
166 In particular circumstances it may be necessary to know the exact
167 nature and order of different substitutions performed by the shell.
168 The exact meaning of certain combinations of quotations is also
169 occasionally important.
170 These are detailed fully in its manual section.
172 The shell has a number of command line option flags mostly of use
173 in writing \s-2UNIX\s0 programs,
174 and debugging shell scripts.
175 See the csh(1) manual section for a list of these options.