DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with the UNIX system shell

Shell programming constructs

The following sections contain models of the shell programming constructs.

Here document

   command <<!
   input lines
   !

For loop

   for variable
   	in this list of values
   do
   	command 1
   	command 2
   	.
   	.
   	.
   	last command
   done

While loop

   while command list
   do
   	command 1
   	command 2
   	.
   	.
   	.
   	last command
   done

If...then

   if
   	this command list is successful
   then
   	command 1
   	command 2
   	.
   	.
   	.
   	last command
   fi

If...then...else

   if
   	this command list is successful
   then
   	command 1
   	command 2
   	.
   	.
   	.
   	last command
   else
   	command 1
   	command 2
   	.
   	.
   	.
   	last command
   fi

Case construction

   case word in
   pattern1)
   	command 1
   	. . .
   	last command
   	;;
   pattern2)
   	command 1
   	. . .
   	last command
   	;;
      .
      .
      .
   last pattern2)
   	command 1
   	. . .
   	last command
   	;;
   esac

Break and continue statements

A break or continue statement forces the program to leave any loop and execute the command following the end of the loop.


Previous topic: Variables used in the system

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004