Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

nested read

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-05-2004
TioTony's Unix or Linux Image
TioTony TioTony is online now Forum Advisor  
Bit Pusher
 
Join Date: Oct 2001
Last Activity: 7 July 2015, 3:26 PM EDT
Location: Southern California
Posts: 339
Thanks: 0
Thanked 2 Times in 2 Posts
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 Unix and Linux 03-05-2004
Perderabo's Unix or Linux Image
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 27 April 2015, 10:26 AM EDT
Location: Ashburn, Virginia
Posts: 9,931
Thanks: 64
Thanked 448 Times in 264 Posts
read ANSWER < /dev/tty
Sponsored Links
    #3  
Old Unix and Linux 03-05-2004
TioTony's Unix or Linux Image
TioTony TioTony is online now Forum Advisor  
Bit Pusher
 
Join Date: Oct 2001
Last Activity: 7 July 2015, 3:26 PM EDT
Location: Southern California
Posts: 339
Thanks: 0
Thanked 2 Times in 2 Posts
Thanks! don't know why that didn't occur to me. Works great.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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:46 PM.