Hi Guys,
I have a scripts that uses a while loop to read a file and set 2 variables.
How can I do this so the variables can be used outside the while loop ?
Below is an example....
# ./junk2 -m -e user
EXE=user master=TRUE
DB_TAG=PRODUCT
In loop MST=MST=testsvr1:3110
In loop ARGS= db=CANDE pw=CANDE
ARGS=
MST=
#
This is the inputfile - junk.dat
#
# DB_TAG DB_NAM DB_PASS DB_SIR DB_PORT DB_DIR DB_MAST DB_JOURNAL DB_NOTE
#
# $Id: sirtab,v 0.1 2005/11/30 06:41:13 18 Exp 18 $
#
# Changes:
# 22/12/06 Changed OLD_PRODUCT etc to PRODUCT and sir2002.
#
DEVMENT CANDE CANDE
#
REBUILD CANDE CANDE
#
PRODUCT CANDE CANDE
KEYPUNCH CANDE CANDE
ARCHIVE CANDE CANDE
AQUARIUM CANDE CANDE
#
This is the script
#!/bin/sh
#set -x
# the question is - why are the variables ARGS and MST not available outside the second loop
#
MORE="TRUE"
while [ ${MORE} = "TRUE" ]
do
case "${1}" in
-ex | -EX | -e | -E)
shift
if [ "${1}X" != "X" ]
then
EXE="${1}"
shift
else
echo No Execution Member Specified
fi
;;
-mst | -MST | -m | -M)
shift
MASTER="TRUE"
;;
*)
MORE="FALSE"
;;
esac
done
echo "EXE=${EXE} master=${MASTER}"
SIRTAB="junk.dat"
AGAIN="TRUE"
while [ ${AGAIN} = "TRUE" ]
do
if read DB_TAG DB_NAM DB_PAS
then
if [ "${DB_TAG}X" = "PRODUCTX" ]
then
echo " DB_TAG=${DB_TAG}"
MST="MST=`uname -n`:3110"
echo " In loop MST=${MST}"
unset ARGS
if [ "${DB_NAM}" != "-" ]
then
ARGS="${ARGS} db=${DB_NAM}"
fi
if [ "${DB_PAS}" != "-" ]
then
ARGS="${ARGS} pw=${DB_PAS}"
echo " In loop ARGS=${ARGS}"
fi
fi
else
AGAIN="FALSE"
fi
done < ${SIRTAB}
echo "ARGS=${ARGS}"
echo "MST=${MST}"
exit 0