KSH: Reading Configuration File With While Loop Issue
I have a ksh script that reads a configuration file, then calls a function with the variable as an argument:
egrep '^[^# ]' $BATCHCONFIG | while read i; do
export VAR1=`echo $i | cut -f1 -d:`
export VAR2=`echo $i | cut -f2 -d:`
export VAR3=`echo $i | cut -f3 -d:`
The problem is that the function that is called calls a binary that sometimes requires user input. The problem is that the user input is then read by the outer while loop and seen as input by the associated read command, thus prempting any chance for the user to provide said input.
I've isolated the issue to the 'while read i; do' loop as the problem does not occur when calling the function manually.
Any ideas how to get around this?
July 10th, 2003, 10:39 AM
Figured it out.... for those who are interested, the solution lay in defining an alternate file descriptor for the configuration file. The following script shows how it works:
while read -u3 i; do
if [ "x`echo $i | egrep '^[^# ]'`" = "x" ]; then
export TARGET=`echo $i | cut -f1 -d:`
export USER=`echo $i | cut -f2 -d:`
echo "Target: $TARGET"
echo "User: $USER"
read dumm #read from stdin
echo "Dummy: $dumm"