Intel XENIX 286 Programmers Guide (86) - Tenox.tc
Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc
XENIX Programming csh: C Shell Starting a Loop at a Terminal It is occasionally useful to use the foreach control structure at the terminal to aid in performing a number of similar commands. For instance, if we want to know how many people have the Bourne shell (/bin/sh) as their login shell, we can give this command: % grep -c /bin/sh$ /etc/passwd if we want to know how many people have the C shell {/bin/csh) as their login shell, we can give this command: % grep -c /bin/csh$ /etc/passwd Since these commands are very similar, we can invoke this foreach command at the terminal to find how many have the Bourne shell and how many have the C shell: % foreach i ('/bin/sh$' '/bin/csh$') ? grep -c $i /etc/passwd ? end Note: When the foreach command is entered at the terminal, the C shell prompts for input with "?" until the end com mand is given. Also useful with loops are variables that contain lists of file names or other words. For example, examine the following terminal session: % set a= (ls) % echo $a csh.n csh.rm % Is csh.n csh.rm % echo $#a 2 The set command here gave the variable a a list of all the file names in the current directory as its value. We can then iterate over these names to perform any chosen function. When the C shell encounters a command enclosed in accent marks (), it executes the command and takes the standard output of the command as the value of the expression formed by the delimited command. The output of a command within accent marks () is converted by the C shell to a list of words. You can also place the quoted string within double quotation marks (") to take each (nonempty) line as a component of the variable. This prevents the lines from being split into words at blanks and tabs. A modifier :x exists which can be used later to expand each component of the variable into another variable by splitting the original variable into separate words at embedded blanks and tabs. 8-19
csh: C Shell XENIX Programming Using Braces with Arguments Another form of file name expansion involves the characters { and }. These characters specify that the contained strings, separated by commas (,), are to be consecutively substituted into the containing characters and the results expanded left to right. Thus expands to A{str1 ,str2,str3}B Astr1B Astr2B ... AstrnB This expansion occurs before the other file name expansions and can be applied recursively (i.e., nested). The results of each expanded string are sorted separately, left to right order being preserved. The resulting file names are not required to exist if no other expansion mechanisms are used. This means that this mechanism can be used to generate arguments that are not file names but that have com mon parts. A typical use of this would be mkdi r -/{hdrs,retrofit,csh} to make subdirectories hdrs, retrofit, and csh in your home directory. This mechanism is most useful when the common prefix is longer, for example: chown root /usr/demo/{file1 ,file2, . .. } Substituting Commands A command enclosed in accent marks () is replaced, just before file names are expanded, by the output from that command. Thus, you can type set pwd = pwd ' to save the current directory in the variable pwd or type * ' vi grep -1 TRACE .c to run the editor vi, supplying as arguments those files whose names end in .c which have the string "TRACE" in them. Command expansion also occurs in input redirected with 11
- Page 124 and 125: XENIX Programming adb: Program Debu
- Page 126 and 127: XENIX Programming adb: Program Debu
- Page 128: XENIX Programming adb: Program Debu
- Page 131 and 132: as: A sse m bier XENIX Programming
- Page 133 and 134: as: Assembler XENIX Programming The
- Page 135 and 136: as: Assembler XENIX Programming Key
- Page 137 and 138: as: Assembler The combination rules
- Page 139 and 140: as: Assembler XENIX Programming Ins
- Page 141 and 142: as: Assembler Initial Value Directi
- Page 143 and 144: as: Assembler XENIX Programming int
- Page 145 and 146: as: A sse m bier sub subb test test
- Page 147 and 148: as: Assembler XENIX Programming lnt
- Page 149 and 150: as: Assembler XENIX Programming lnt
- Page 151 and 152: as: Assembler XENIX Programming Imm
- Page 153 and 154: as: A sse m bier XENIX Programming
- Page 156 and 157: CHAPTER 8 csh : C SHEll The C shell
- Page 158 and 159: XENIX Programming csh: C Shell Some
- Page 160 and 161: XENIX Programm ing *w 32 * q % !c -
- Page 162 and 163: XENIX Programming csh: C Shell the
- Page 164 and 165: XENIX Programming csh: C Shell Usin
- Page 166 and 167: XENIX Programming csh: C Shell Usin
- Page 168 and 169: XENIX Programming csh: C Shell The
- Page 170 and 171: XENIX Programming csh: C Shell Note
- Page 172 and 173: XENIX Programming switch ( string c
- Page 176 and 177: XENIX Programming csh: C Shell Spec
- Page 178 and 179: CHAPTER 9 lex : LEXICAL ANA LYZER G
- Page 180 and 181: XENIX Programming lex: Lexical Anal
- Page 182 and 183: XENIX Programming lex: Lexical Anal
- Page 184 and 185: XENIX Programming lex: Lexical Anal
- Page 186 and 187: XENIX Programming lex: Lexical Anal
- Page 188 and 189: XENIX Programming lex: Lexical Anal
- Page 190 and 191: XENIX Programming lex: Lexical Anal
- Page 192 and 193: XENIX Programm ing lex: Lexical Ana
- Page 194 and 195: XENIX Programming Specifying Source
- Page 196 and 197: XENIX Programming lex: Lexical Anal
- Page 198 and 199: XENIX Programming lex: Lexical Anal
- Page 200 and 201: XENIX Programming The definitions s
- Page 202 and 203: CHAPTER 10 yacc: COMPILER-COMPILER
- Page 204 and 205: XENIX Programming yacc: Compiler-Co
- Page 206 and 207: XENIX Programming yacc: Compiler-Co
- Page 208 and 209: XENIX Programming yacc: Compiler-Co
- Page 210 and 211: XENIX Programming yacc: Compiler-Co
- Page 212 and 213: XENIX Programming yacc: Compiler-Co
- Page 214 and 215: XENIX Programming yacc: Compiler-Co
- Page 216 and 217: XENIX Programming yacc: Compiler-Co
- Page 218 and 219: XENIX Programming yacc: Compiler-Co
- Page 220 and 221: XENIX Programming yacc: Compiler-Co
- Page 222 and 223: XENIX Programming yacc: Compiler-Co
csh: C Shell <strong>XENIX</strong> Programming<br />
Using Braces with Arguments<br />
Another form of file name expansion involves the characters { and }. These characters<br />
specify that the contained strings, separated by commas (,), are to be consecutively<br />
substituted into the containing characters and the results expanded left to right. Thus<br />
expands to<br />
A{str1 ,str2,str3}B<br />
Astr1B Astr2B ... AstrnB<br />
This expansion occurs before the other file name expansions and can be applied<br />
recursively (i.e., nested). The results of each expanded string are sorted separately, left<br />
to right order being preserved. The resulting file names are not required to exist if no<br />
other expansion mechanisms are used. This means that this mechanism can be used to<br />
generate arguments that are not file names but that have com mon parts.<br />
A typical use of this would be<br />
mkdi r -/{hdrs,retrofit,csh}<br />
to make subdirectories hdrs, retrofit, and csh in your home directory. This mechanism<br />
is most useful when the common prefix is longer, for example:<br />
chown root /usr/demo/{file1 ,file2, . .. }<br />
Substituting Commands<br />
A command enclosed in accent marks () is replaced, just before file names are expanded,<br />
by the output from that command. Thus, you can type<br />
set pwd = pwd '<br />
to save the current directory in the variable pwd or type<br />
* '<br />
vi grep -1 TRACE .c<br />
to run the editor vi, supplying as arguments those files whose names end in .c which<br />
have the string "TRACE" in them. Command expansion also occurs in input redirected<br />
with 11