Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc

09.06.2013 Views

XENIX Programming switch ( string case string 1: commands breaksw case stringn: commands breaksw default: commands breaksw endsw csh: C Shell For details see csh in Appendix B. C programmers should note that breaksw is used to exit from a switch while break exits from a while or foreach loop. A common mistake to make in C shell scripts is to use break rather than breaksw in switches. Finally, the C shell supports a goto statement, with labels looking like they do in C, e.g.: loop: commands goto loop Supplying Input to Commands Commands run from C shell scripts receive by default the standard input of the C shell running the script. This feature enables C shell scripts to fully participate in pipelines but mandates extra notation for commands that take inline data. Thus we need a metanotation for supplying inline data to commands in C shell scripts. For example, consider this script that runs the editor to delete leading blanks from the lines in each argument file: # deblank -- rem ove leading blanks foreach i ($argv) ed - $i

csh: C Shell XENIX Programming The notation < < ' EOF' means that the standard input for the ed command is to come from the text in the C shell script file up to the next line consisting of exactly EOF. Because EOF is quoted in single quotation marks ('), the C shell does not perform variable substitution on the intervening lines. In general, if any part of the word following the 11

<strong>XENIX</strong> Programming<br />

swi<strong>tc</strong>h ( string<br />

case string 1:<br />

commands<br />

breaksw<br />

case stringn:<br />

commands<br />

breaksw<br />

default:<br />

commands<br />

breaksw<br />

endsw<br />

csh: C Shell<br />

For details see csh in Appendix B. C programmers should note that breaksw is used to<br />

exit from a swi<strong>tc</strong>h while break exits from a while or foreach loop. A common mistake<br />

to make in C shell scripts is to use break rather than breaksw in swi<strong>tc</strong>hes.<br />

Finally, the C shell supports a goto statement, with labels looking like they do in C, e.g.:<br />

loop:<br />

commands<br />

goto loop<br />

Supplying Input to Commands<br />

Commands run from C shell scripts receive by default the standard input of the C shell<br />

running the script. This feature enables C shell scripts to fully participate in pipelines<br />

but mandates extra notation for commands that take inline data.<br />

Thus we need a metanotation for supplying inline data to commands in C shell scripts.<br />

For example, consider this script that runs the editor to delete leading blanks from the<br />

lines in each argument file:<br />

# deblank -- rem ove leading blanks<br />

foreach i ($argv)<br />

ed - $i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!