Subject: Variables in Loops in Scripts
To: None <netbsd-help@netbsd.org>
From: C Kane <ckane@best.com>
List: netbsd-help
Date: 01/19/1999 17:44:51
Hello.

I have a simple sh/ksh script which works okay under
Solaris and HP-UX, but fails in the same way under
NetBSD and Linux.  After the "do" loop is over, the
variables that are set inside the loop revert to their
previous before-the-loop values.  What am I doing wrong
in the following script?

Thanks..
-- Chuck


#!/bin/ksh

ps -ax | while read PID TT STAT TIME COMMAND ARGS
do
  case $COMMAND in
    syslogd  ) SYSLOGD=$PID ;;
    portmap  ) PORTMAP=$PID ;;
    update   ) UPDATE=$PID ;;
  esac
  echo syslogd=$SYSLOGD portmap=$PORTMAP update=$UPDATE
done

echo FINAL syslogd=$SYSLOGD portmap=$PORTMAP update=$UPDATE