From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dealer.Cards.COM ([192.133.70.2]) by hawkwind.utcs.toronto.edu with SMTP id <2060>; Wed, 15 Sep 1993 13:38:09 -0400 Received: from monte (monte.cards.com) by dealer.Cards.COM (4.1/mls/3.2) id AA07316; Wed, 15 Sep 93 13:37:44 EDT Message-Id: <9309151737.AA07316@dealer.Cards.COM> Received: by monte (4.1/mls/3.2) id AA04685; Wed, 15 Sep 93 13:37:43 EDT From: carvell@Cards.COM Subject: Need help with input loop (long) To: rc@hawkwind.utcs.toronto.edu Date: Wed, 15 Sep 1993 13:37:42 -0400 Content-Type: text Folks, I'm having a strange problem and I hoped some kind soul out there could help me. I'm sure i'ts something obvious but for the life of me I can't spot it. I am using a Sun SPARC IPC running SunOS 4.1.3. My rc was compiled with gcc and includes GNU readline. Below is a scaled down version of the script which exhibits the behavior in question. What I would LIKE to see happen is, I type in lines of text and each line is echoed. When I hit ^D to end my input, the break should execute, and the script should drop out of the while loop and exit. What is ACTUALLY happening is, when I hit ^D, I get an error "read: Bad file number" and a message "Your input was: BOTTOM OF LOOP". Then it goes back to the top of the loop (even though the trace shows that break is being executed!!!) and gives me another prompt. It looks like the echo at the bottom of the loop is being fed back into line. To implement my read function, I'm using the UNIX (or at least Sun UNIX) line program. Basically it echoes input from stdin, and returns a status of 1 on eof (I've verified this). If any of you rc gurus can show me what I'm doing wrong, I would REALLY REALLY appreciate it. Sadly, I'm the only rc user at my site; everybody else here is still in the dark ages with /bin/sh. Gary -- Gary Carvell Galaxy Global Corporation Mail: carvell@cards.com Voice: 304-363-1759 Fax: 304-363-1766 - - - file: trythis - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #!/usr/local/bin/rc # read var # read stdin into a variable; return a status of 1 on eof fn read { $1=`{/usr/bin/line; if(! ~ $status 0) return 1} } fn trythis { while() { echo -n '-> ' read input if(! ~ $status 0) break echo Your input was: $input } echo BOTTOM OF LOOP } trythis - - - sample output - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /home/dealer/carvell- trythis -> hi there Your input was: hi there -> testing Your input was: testing -> read: Bad file number <--- [here I hit ^D at the prompt] Your input was: BOTTOM OF LOOP -> read: Bad file number "" Your input was: BOTTOM OF LOOP -> read: Bad file number "" Your input was: BOTTOM OF LOOP -> ^C /home/dealer/carvell- - - - sample output when using -x flag on rc - - - - - - - - - - - - - - - - - /home/dealer/carvell- trythis fn read {$1=`{/usr/bin/line;if(! ~ $status 0)return 1}} fn trythis {while(()){echo -n '-> ';read input;if(! ~ $status 0)break;echo Your inp ut was: $input};echo BOTTOM OF LOOP} trythis echo -n '-> ' -> read input /usr/bin/line hi there ~ 0 0 input=(hi there) ~ 0 0 echo Your input was: hi there Your input was: hi there echo -n '-> ' -> read input /usr/bin/line testing ~ 0 0 input=testing ~ 0 0 echo Your input was: testing Your input was: testing echo -n '-> ' -> read input /usr/bin/line ~ 1 0 return 1 ~ 1 0 break echo BOTTOM OF LOOP read: Bad file number <----- !!!! input=(BOTTOM OF LOOP) ~ 0 0 echo Your input was: BOTTOM OF LOOP Your input was: BOTTOM OF LOOP echo -n '-> ' -> read input /usr/bin/line ~ 1 0 return 1 ~ 1 0 break echo BOTTOM OF LOOP read: Bad file number <----- !!!! input=(BOTTOM OF LOOP) ~ 0 0 echo Your input was: BOTTOM OF LOOP Your input was: BOTTOM OF LOOP echo -n '-> ' -> read input /usr/bin/line ~ 1 0 return 1 ~ 1 0 break echo BOTTOM OF LOOP read: Bad file number <----- !!!! input=(BOTTOM OF LOOP) ~ 0 0 echo Your input was: BOTTOM OF LOOP Your input was: BOTTOM OF LOOP echo -n '-> ' -> read input /usr/bin/line ^C /home/dealer/carvell-