rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
From: carvell@Cards.COM
To: rc@hawkwind.utcs.toronto.edu
Subject: Need help with input loop (long)
Date: Wed, 15 Sep 1993 13:37:42 -0400	[thread overview]
Message-ID: <9309151737.AA07316@dealer.Cards.COM> (raw)

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-



             reply	other threads:[~1993-09-15 17:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-09-15 17:37 carvell [this message]
1993-09-15 18:52 Alan Watson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9309151737.AA07316@dealer.Cards.COM \
    --to=carvell@cards.com \
    --cc=rc@hawkwind.utcs.toronto.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).