UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old July 9th, 2003, 04:31 PM
aaamr aaamr is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 4 aaamr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old July 10th, 2003, 09:39 AM
aaamr aaamr is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 4 aaamr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > KSH: Reading Configuration File With While Loop Issue


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway