6.19. Program Control Statements

 <  Day Day Up  >  

6.19.1 next Statement

The next statement gets the next line of input from the input file, restarting execution at the top of the awk script.

Example 6.133.
 (In Script) { if ( ~ /Peter/){next}     else {print} } 

EXPLANATION

If the first field contains Peter , awk skips over this line and gets the next line from the input file. The script resumes execution at the beginning.

6.19.2 exit Statement

The exit statement is used to terminate the awk program. It stops processing records, but does not skip over an END statement. If the exit statement is given a value between 0 and 255 as an argument ”in the following example, it is exit (1) ”this value can be printed at the command line to indicate success or failure by typing the following.

Example 6.134.
 (In Script)    {exit (1) } (The Command Line) %  echo $status   (csh)   1  $  echo $?   (sh/ksh)   1  

EXPLANATION

An exit status of 0 indicates success, and an exit value of nonzero indicates failure (a convention in UNIX). It is up to the programmer to provide the exit status in a program. The exit value returned in this example is 1.

 <  Day Day Up  >  


UNIX Shells by Example
UNIX Shells by Example (4th Edition)
ISBN: 013147572X
EAN: 2147483647
Year: 2004
Pages: 454
Authors: Ellie Quigley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net