It is currently Tue, 30 Nov 2021 18:18:05 GMT



 
Author Message
 code for "read" function of bourne shell
Hello,

Does anyone know what the code looks like for the "read"
function of the bourne/bash/ksh shells ?  And, how does it
assign the values it reads to the variables of the shell
it is called from ?

For example,

bash 504>  echo $EDITOR
vi
bash 505> read EDITOR
emacs
bash 506> echo $EDITOR
emacs

Thanks for any help on the internals of "read".  Bruce



 Tue, 04 May 2004 23:39:45 GMT   
 code for "read" function of bourne shell
In article <26f31657.0111160739.20d5a...@posting.google.com>,

It's not called from a shell.  It's part of the shell:

        $ type read
        read is a shell builtin
        $

That's why it can modify the shell's variables.

Other than that, the only interesting thing about read is that
sometimes it does a separate read() system call for each byte of the
line it reads.  It does this when reading from a pipe, for example.
So it's not necessarily the most efficient thing imaginable.

  - Logan
--
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos



 Thu, 06 May 2004 05:55:51 GMT   
 code for "read" function of bourne shell

You can emulate this by opening STDIN, reading till EOL,
then do a putenv() on the command-line ARG.

-Andy M
http://synecdoche.net/~andy



 Sat, 08 May 2004 08:05:04 GMT   
 code for "read" function of bourne shell

 Logan> Other than that, the only interesting thing about read is that
 Logan> sometimes it does a separate read() system call for each byte
 Logan> of the line it reads.  It does this when reading from a pipe,
 Logan> for example.

It's required to do that, for reasons which should be obvious if you
consider the consequences of mixing read commands and programs which
read from stdin in the same script.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>



 Sat, 08 May 2004 09:49:32 GMT   
 
   [ 4 post ] 

Similar Threads

1. Bourne shell "read line"

2. Q about Bourne shell "read" command

3. Bourne shell: "no stack space" problem

4. Bourne shell "trip test"?

5. Bourne shell equivilant of "source"

6. Bourne Shell Script to "C" Converter

7. "unset" variables under ultrix bourne shell

8. "read" shell command

9. Borne Shell problem with "while read".


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