It is currently Fri, 15 Oct 2021 21:08:32 GMT

Author Message
 read a line in rc
How can I read a line from tty into a shell-variable in rc?
I'm sure there is a simple solution to this, but I can't find it!

Thanks in advance.

        Magnus Homann                   "The future is so bright,                you gotta wear shades..."

 Fri, 11 Mar 1994 22:25:44 GMT   
 read a line in rc
In <> (Magnus Homann) writes:

In [Duf90] there is an example program called ``holmdel'',

Duff>                                                      in which the
Duff> players alternately name Bell Labs Locations, the winner being the
Duff> first to mention Holmdel.
Duff> This script is worth describing in detail (rather, it would be if it
Duff> weren't so silly.)

The there used function `read' is defined as follows:

fn read {
        $1 = `{awk '{print;exit}'}

As you see this is a simple solution and everybody *must* find it :-)

[Duf90] Tom Duff, ``Rc - A Shell for Plan 9 and UNIX Systems'', Proc. of the
        Summer 1990 UKUUG Conf., London, July, 1990, pp. 21-33

Guenther H. Leber  Technical University Vienna   Voice: +43/222/58801-8176
                   Dept. for Real-Time Systems   Fax:   +43/222/569149
E-mail:           All eyes were on Ford Prefect,
            Don't panic!                       some of them were on stalks.

 Sat, 12 Mar 1994 23:54:12 GMT   
 read a line in rc

I have now recieved numerous answers on my question.

Thanks all for pointing out the obvious:

; var=`line

        Magnus Homann                   "The future is so bright,                you gotta wear shades..."

 Sun, 13 Mar 1994 06:04:08 GMT   
 read a line in rc

...which is, of course, not portable.  Numerous BSD-based systems do not
include `line'.

``Teach them politics and war so their sons may study medicine and mathematics
in order to give their children a right to study painting, poetry, music, and
Chet Ramey, CWRU  Inet: c...@po.CWRU.Edu   NeXT Mail: c...@macbeth.INS.CWRU.Edu

 Sun, 13 Mar 1994 23:25:17 GMT   
 read a line in rc

 'line' is a pretty trivial program to write; my version (written
before I'd heard about the real line) is 21 lines, including error
checking. I'll be happy to mail a shar to interested parties.

 "var=`{awk '{print;exit}'}" doesn't work if standard input is a file or
a pipe, instead of a terminal (try it and see; the awk gobbles up a
buffer's worth of standard input before printing its one line). Neither
does 'sed 1q' or a number of other things; you need something that
stops after a line and doesn't use buffering, which is just what 'line'

 "var=`{line}" suffices for a one-shot, but if you want to check
for EOF, you need to use something like:
        # (assume $nl is just a newline)
        var=`` $nl {line; echo $status}
        if (! ~ $#var 2 || ! ~ $var(2) 0)
        var=`{echo $var(1)}
which uses a sleazy trick to get the status of line as well, as "`"
always has a status of 0.

                V9: the kernel where you can do
                        fgrep <something> */*.[ch]
                and not get "Arguments too long".                 ...!{utgpu,utzoo,watmath}!utgpu!cks

 Wed, 16 Mar 1994 11:28:33 GMT   
   [ 5 post ] 

Similar Threads

1. read from stdin while reading line by line a file

2. line by line reading of the lines in list

3. SOLVED - Raid rc.0, rc.6 rc.S

4. Reading a script file line by line.

5. How to read line by line in csh

6. Read line at at time and split up that line

7. Using read within a loop that parses a file line by line

8. read pipe line by line

9. reading files line-be-line?

10. read a file line by line in csh script

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software