rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re: Need help with input loop (long)
@ 1993-09-15 18:52 Alan Watson
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Watson @ 1993-09-15 18:52 UTC (permalink / raw)
  To: rc

> fn read {
>   $1=`{/usr/bin/line; if(! ~ $status 0) return 1}
> }

I believe your attempt to return from a command substitution within a
function is causing rc to get thoroughly confused.  I must admit that I
can't decide whether to be appalled or impressed by your novel use of
this construct!

Getting read right it tricky.  I recommend the read command in the FAQ
(although make sure you have $nl defined -- fixed in the next
version).

Alan.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Need help with input loop (long)
@ 1993-09-15 17:37 carvell
  0 siblings, 0 replies; 2+ messages in thread
From: carvell @ 1993-09-15 17:37 UTC (permalink / raw)
  To: rc

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-



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1993-09-15 18:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-09-15 18:52 Need help with input loop (long) Alan Watson
  -- strict thread matches above, loose matches on Subject: below --
1993-09-15 17:37 carvell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).