AIX Tip of the Week

AIX Tip of the Week: Korn Shell Job Control

Audience: AIX Administrators and End Users

Date: February 4, 2000

Three useful Korn shell commands for controlling job flow based on the outcome of other processes are &&, || and wait. They work as follows:

a && b               #  run "b" if "a" completes successfully
a || b      	     #  run "b" if "a" fails
wait		     #  wait for completion of one or more background jobs to complete before proceeding.

In the above examples, "a", "b" and "c" can be UNIX commands, shell scripts, executables, or combinations thereof. Here's an illustration of how the "wait" command works:

#!/usr/bin/ksh
a &
b &
wait
c

Jobs "a" and "b" are started in the background (&). The "wait" command waits for both "a" and "b" to complete before starting "c". In this example the wait command waits for all background processes to complete. However, the wait command can be directed to wait for specific processes. Refer to the man pages for more information.