Running 'exec' twice in one UNIX shell script

This is a discussion on Running 'exec' twice in one UNIX shell script within the Tech Board forums, part of the Community Boards category; I have two programs that need to be executed one right after another. I'm trying to write a little shell ...

Running 'exec' twice in one UNIX shell script

I have two programs that need to be executed one right after another. I'm trying to write a little shell script with two calls to exec, but it stops after the first program completes. Here's what I've got:

#! /usr/bin/sh
exec prog1 $1 $2
exec prog2 $2

Do I need to put these in a loop or something? I'm really new to shell programming so I don't really have any idea what to do to fix this. Thanks.

That did the trick. Apparently when 'exec' finishes it kills the shell, therefore not allowing any other program to run. (I tried typing 'exec prog1' in the terminal window and the terminal closed on me). Thanks alot.