|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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:` do_something $VAR3 done 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? -A. |
|
#2
|
|||
|
|||
|
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:
#!/bin/ksh while read -u3 i; do if [ "x`echo $i | egrep '^[^# ]'`" = "x" ]; then continue fi 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" done 3<test.conf |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > KSH: Reading Configuration File With While Loop Issue |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|