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 Note: When setting $status (as in the cmp statement above), the status will change if anything is done between the cmp statement and the "if ($status != 0) then" statement. For example: cmp -s $i -/backup/$i :t # to set $status echo $status if ($status ! = 0) then The other control construct is a statement of the form if (expression) then command end if # if fi les are different, status = 1 # will echo 1 , but status will be set to 0 # now status = 0, but it should be 1 The placement of the keywords in this statement is not flexible due to the current implementation of the C shell. The following two formats are not acceptable to the C shell: and if (expression) # Won't work! then command end if if (expression) then command endif # Won't work The C shell does have another form of the if statement: if (expression) command which can be written if (expression) \ command Here we have escaped the newline for the sake of appearance. The command must not involve "1", "&", or ";" and must not be another control command. The second form requires the final backslash {\) to immediately precede the end-of-line. The more general if statements above also ad mit a sequence of else-if pairs followed by a single else and an endif, for example: if (expression) then commands else if (expression) then commands else end if commands 8-15
csh: C Shell XENIX Programming Another important mechanism used in C shell scripts is the colon (:) modifier. We can use the modifier :r here to extract the root of a file name. For example, this gives the variable i the value /mnt/foo.bar: % set i = /mnt/foo.bar If you give this command: % echo $i $i:r the result is /mnt/foo.bar /mnt/foo This example shows how the :r modifier strips off the trailing ".bar". Other modifiers take off the last component of a path name leaving the head :h or all but the last component of a path name leaving the tail :t. These modifiers are fully described in the entry csh in Appendix B, "Programming Commands." You can also use the command substitution mechanism to perform modifications on strings and then re-enter the C shell environment. Since each usage of this mechanism involves the creation of a new process, it is much more expensive to use than the colon (:) modification mechanism. Note also that the current implementation of the C shell limits the number of colon modifiers on a "$" substitution to 1. Thus produces % set i = /albic % echo $i $i:h:t !albic /a/b:t and does not do what you might expect. Finally, we note that the number sign (#) lexically introduces a C shell comment in C shell scripts (but not from the terminal). All subsequent characters on the input line after a number sign are discarded by the C shell. This character can be quoted using ' or \ to place it in an argument word. Using Other Control Structures The C shell also has control structures while and switch similar to those of C. These take the forms and 8-16 while ( expression ) commands end
- Page 120 and 121: XENIX Programming adb: Program Debu
- Page 122 and 123: XENIX Programming adb: Program Debu
- 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 172 and 173: XENIX Programming switch ( string c
- Page 174 and 175: XENIX Programming csh: C Shell Star
- 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
<strong>XENIX</strong> Programming csh: C Shell<br />
Note: When setting $status (as in the cmp statement above), the status will change if<br />
anything is done between the cmp statement and the "if ($status != 0) then" statement.<br />
For example:<br />
cmp -s $i -/backup/$i :t # to set $status<br />
echo $status<br />
if ($status ! = 0) then<br />
The other control construct is a statement of the form<br />
if (expression) then<br />
command<br />
end if<br />
# if fi les are different, status = 1<br />
# will echo 1 , but status will be set to 0<br />
# now status = 0, but it should be 1<br />
The placement of the keywords in this statement is not flexible due to the current<br />
implementation of the C shell. The following two formats are not acceptable to the C<br />
shell:<br />
and<br />
if (expression) # Won't work!<br />
then<br />
command<br />
end if<br />
if (expression) then command endif # Won't work<br />
The C shell does have another form of the if statement:<br />
if (expression) command<br />
which can be written<br />
if (expression) \<br />
command<br />
Here we have escaped the newline for the sake of appearance. The command must not<br />
involve "1", "&", or ";" and must not be another control command. The second form<br />
requires the final backslash {\) to immediately precede the end-of-line.<br />
The more general if statements above also ad mit a sequence of else-if pairs followed by<br />
a single else and an endif, for example:<br />
if (expression) then<br />
commands<br />
else if (expression) then<br />
commands<br />
else<br />
end if<br />
commands<br />
8-15