nested read | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

nested read

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-05-2004
TioTony's Avatar
TioTony TioTony is offline Forum Advisor  
Bit Pusher
 
Join Date: Oct 2001
Last Activity: 16 October 2014, 1:04 AM EDT
Location: Southern California
Posts: 332
Thanks: 0
Thanked 1 Time in 1 Post
nested read

I am hoping someone can help me with this one.

I am writing a ksh script on Solaris. I want to read in host names and some other info from a file, do an "rsh host 'shutdown'" (or any uname for now until I get it working), and then be given some options. The problem is I am using while read LINE do with a nested read like this:



Code:
cat hosts.lst | while read LINE
do
   set ${LINE}
   rsh ${1} 'uname -a'
   DONE=false
   while [[ ${DONE} = false ]]
   do
      echo "[C]heck, [K]ill, [G]o?"
      read ANSWER
      ANSWER=`echo ${ANSWER} | tr -s '[:lower:]' '[:upper:]'`
      echo "ANSWER is ${ANSWER}"
      case ${ANSWER} in
         C ) check_running_processes;;
         K ) kill_running_processes;;
         G ) DONE=true;; #go to next priority
       esac
   done

This isn't the entire script just the section I am having problems with. The problem I cannot get around is when I try to "read ANSWER", $ANSWER is getting the value of $LINE for that iteration. I understand why this is happening but cannot figure out how to get around it.

I have tried putting the read in (), in a separate subroutine, unsetting $LINE, setting $LINE to something else.

Any other ideas?

Thanks,
Tony
Sponsored Links
    #2  
Old 03-05-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 28 October 2014, 3:35 PM EDT
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 64
Thanked 437 Times in 261 Posts
read ANSWER < /dev/tty
Sponsored Links
    #3  
Old 03-05-2004
TioTony's Avatar
TioTony TioTony is offline Forum Advisor  
Bit Pusher
 
Join Date: Oct 2001
Last Activity: 16 October 2014, 1:04 AM EDT
Location: Southern California
Posts: 332
Thanks: 0
Thanked 1 Time in 1 Post
Thanks! don't know why that didn't occur to me. Works great.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Faster than nested while read loops? chstr_14 UNIX for Dummies Questions & Answers 4 08-09-2011 01:52 PM
Help nested sql joje47 Programming 1 05-31-2011 11:25 AM
sed in awk ? or nested awk ? varungupta UNIX for Advanced & Expert Users 11 02-08-2008 09:34 AM
while read loop w/ a nested if statement - doesn't treat each entry individually littlefrog Shell Programming and Scripting 7 12-11-2007 08:49 PM
Nested while read line loop Rakker Shell Programming and Scripting 7 06-24-2005 07:42 AM



All times are GMT -4. The time now is 03:00 AM.