rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re: A patch to add builtin read (small bug)
@ 1993-09-23 16:03 gjv%atlas%cesar
  0 siblings, 0 replies; 5+ messages in thread
From: gjv%atlas%cesar @ 1993-09-23 16:03 UTC (permalink / raw)
  To: rc%hawkwind.utcs.toronto.edu%m_internet%m_mailnow%hermes.DECnet


[Tom wrote:]
 |At least one of those bug fixes I mentioned prevents a crash, you really
 |should look into them.

Ok, someone has a "jumbo" patch against a vanilla 1.4 ? (saves me from
scanning the archive for the actual patches).

 |[ Re: read x;eval 'x=('$x')']
 |
 |Yeah, it's a stunt, and I should have made the standard disclaimer that
 |pathalogical cases would kill it.

A hopefully not_so_pathological example:

   The password file may have * in the password field for some special
   users, which gets expanded to all files in the current directory...

 |[ Re: ifs aware read function]
 |
 |Because you lose information that you can't get back.  For example if
 |you are trying to parse the entries from /etc/passwd to find the home
 |directories, and the comment field is blank:
 |
 |[example with blank fields deleted]
 |
 |and when you try to retrieve $x(6) which should be the directory you get
 |/bin/rc instead!  This may not be the worlds best example but I hope my
 |point is clear.  The way read works now preserves potentially important
 |information.

Ok, good example, but an ifs aware read still allows you to set ifs to
newline before reading, giving you the functionality of the current read.

The risk of loosing information is my responsability I think, it is not
up to the read function to keep me from doing so.

	Gert-Jan

---------------------------------------------------
J.G. Vons   E-Mail: vons@cesar.crbca1.sinet.slb.com


^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: A patch to add builtin read (small bug)
@ 1993-09-23 18:10 Tom Culliton x2278
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Culliton x2278 @ 1993-09-23 18:10 UTC (permalink / raw)
  To: arnold, culliton, rc, vons

<Arnold suggests>
> Doesn't rc fork builtins when they're redirected?  This may be why
> redirections on read didn't show up in /bin/sh until System III or
> System V.

That sounds like the right answer to me and since no other builtin
command takes input... Sigh... This is looking like a bigger job than
expected.  If it's not obvious how to fix this I may withdraw the read
patch until someone can do it right.

Tom


^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: A patch to add builtin read (small bug)
@ 1993-09-23 15:36 Arnold Robbins
  0 siblings, 0 replies; 5+ messages in thread
From: Arnold Robbins @ 1993-09-23 15:36 UTC (permalink / raw)
  To: Tom Culliton x2278, rc, vons

> Doing:
> 
> 	read x </etc/passwd
> 
> doesn't work either, but my brain isn't working well emough at the
> moment to figure out why.  Anybody got a clue?

Doesn't rc fork builtins when they're redirected?  This may be why
redirections on read didn't show up in /bin/sh until System III or System V.

(One of the sh man pages from ~ 5.0 says something like "redirections on
read are *now* allowed" - emphasis mine.)

Arnold


^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: A patch to add builtin read (small bug)
@ 1993-09-23 15:19 Tom Culliton x2278
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Culliton x2278 @ 1993-09-23 15:19 UTC (permalink / raw)
  To: rc, vons

> The patch dropped in nicely in my virgin 1.4, no problems.

At least one of those bug fixes I mentioned prevents a crash, you really
should look into them.

> I was just wondering about the following case:
> 
> 	; x=(foo bar)
> 	; read x < /dev/null
> 	; echo $status
> 	1
> 	; whatis x
> 	x=(foo bar)
> 
> This suggests that something has been read before encountering EOF,
> which is obviously not the case, so I assume the read should set x to ''.

Doing:

	read x </etc/passwd

doesn't work either, but my brain isn't working well emough at the
moment to figure out why.  Anybody got a clue?

>   |For Chris, if you don't care about setting a different ifs, you can
>   |split the line without a fork by using eval:
>   |	read x;eval 'x=('$x')'
>
> This doesn't work:

(Examples with embedded '#' and '=' deleted)

Yeah, it's a stunt, and I should have made the standard disclaimer that
pathalogical cases would kill it.

> If a read function is added, why not make it a bit more practical by using
> $ifs? If makes it more useful, and the code above a bit more elegant.
> I wouldn't mind adding this myself, but I'm not too familiar with the
> rc internals.
> 
> 	Gert-Jan

Because you lose information that you can't get back.  For example if
you are trying to parse the entries from /etc/passwd to find the home
directories, and the comment field is blank:

	joeblow:x:200:50::/usr/joeblow:/bin/rc

You get the following list:

	x=(joeblow x 200 50 /usr/joeblow /bin/rc)

and when you try to retrieve $x(6) which should be the directory you get
/bin/rc instead!  This may not be the worlds best example but I hope my
point is clear.  The way read works now preserves potentially important
information.

Tom


^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: A patch to add builtin read (small bug)
@ 1993-09-23  7:30 gjv%atlas%cesar
  0 siblings, 0 replies; 5+ messages in thread
From: gjv%atlas%cesar @ 1993-09-23  7:30 UTC (permalink / raw)
  To: rc%hawkwind.utcs.toronto.edu%m_internet%m_mailnow%hermes.DECnet


 |                 The diffs assume you've been keeping up with the bug
 |fix patches posted here.  (If anyone wants a complete set of diffs
 |against a virgin copy of 1.4 let me know and I'll mail it to you.)

The patch dropped in nicely in my virgin 1.4, no problems.

I was just wondering about the following case:

	; x=(foo bar)
	; read x < /dev/null
	; echo $status
	1
	; whatis x
	x=(foo bar)

This suggests that something has been read before encountering EOF,
which is obviously not the case, so I assume the read should set x to ''.

  |For Chris, if you don't care about setting a different ifs, you can
  |split the line without a fork by using eval:
  |	read x;eval 'x=('$x')'

This doesn't work:

	; read x;eval 'x=('$x')'
	a line with a # in the middle
	line 1: syntax error near eof
	;

	; read x;eval 'x=('$x')'
	a line with a = in the middle
	line 1: syntax error near '='
	;

The 'trick' with the echo works however, fork()-ing every time:

	; read x; x= `{echo $x}
	a line with a # in the middle
	; whatis x
	x=(a line with a '#' in the middle)
	;

If a read function is added, why not make it a bit more practical by using
$ifs? If makes it more useful, and the code above a bit more elegant.
I wouldn't mind adding this myself, but I'm not too familiar with the
rc internals.

	Gert-Jan

---------------------------------------------------
J.G. Vons   E-Mail: vons@cesar.crbca1.sinet.slb.com


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

end of thread, other threads:[~1993-09-23 22:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-09-23 16:03 A patch to add builtin read (small bug) gjv%atlas%cesar
  -- strict thread matches above, loose matches on Subject: below --
1993-09-23 18:10 Tom Culliton x2278
1993-09-23 15:36 Arnold Robbins
1993-09-23 15:19 Tom Culliton x2278
1993-09-23  7:30 gjv%atlas%cesar

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).