rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re: early reaction(s) to rc
@ 1991-08-23 20:47 Arnold D. Robbins
  1991-08-24  0:15 ` John Mackin
  0 siblings, 1 reply; 4+ messages in thread
From: Arnold D. Robbins @ 1991-08-23 20:47 UTC (permalink / raw)
  To: Boyd Roberts, rc

> Duff told me:
> 
>     rcmain does the flags that affect initialization, to wit:
>           -p      `protected' -- don't read functions, set path=(. /bin)
>           -c      execute a command given on the command line
>           -i      `interactive' -- print prompts for commands
>           -l      `login shell' -- read $home/lib/profile before user's commands

I would love to know how this works.  -c is trivial:

	eval $*(2) ; exit

and so is -l, but -p and -i are harder --- is there some secret equivalent
of `set' in his rc?  In other words, how does the rc program tell the
shell itself what to do with the environment and whether or not to prompt?

Thanks,

Arnold


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

* Re: early reaction(s) to rc
  1991-08-23 20:47 early reaction(s) to rc Arnold D. Robbins
@ 1991-08-24  0:15 ` John Mackin
  1991-08-24  3:48   ` John Mackin
  0 siblings, 1 reply; 4+ messages in thread
From: John Mackin @ 1991-08-24  0:15 UTC (permalink / raw)
  To: The rc Mailing List

Arnold writes, in relation to rcmain:

    I would love to know how this works.  -c is trivial:

    	eval $*(2) ; exit

    and so is -l, but -p and -i are harder --- is there some secret equivalent
    of `set' in his rc?  In other words, how does the rc program tell the
    shell itself what to do with the environment and whether or not to prompt?

I second the first comment; for quite a while I've wanted to have a look
at a real Tenth Edition (as opposed to Plan 9, if there is a difference)
rcmain.  Boyd, do you reckon if you ask td to mail you one, he will?  I
have some general comments to make about rcmain which I will send later
today, right now I have to get off to work -- but I just thought I should
point out that -p doesn't require any support beyond what our rc already
has:

eval `{ whatis | rev | sed -n -e '/ nf$/s/^.*{\(.*\)$/\1/p' | rev }

You can't really do without the two rev's, since there's no way to be
sure your r.e. is matching the function name correctly if you try that
(consider that function names, if quoted, may contain both space and
left-curly-bracket).  But that certainly does the job of removing
functions from the environment.  (Of course, in a real rcmain, all
the commands above -- eval, whatis, rev, sed, and rev -- would be
prefixed by `builtin' to avoid being subverted by functions before
they could accomplish the task of deleting them.  I have omitted this
here for clarity.)

OK,
John.


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

* Re: early reaction(s) to rc
  1991-08-24  0:15 ` John Mackin
@ 1991-08-24  3:48   ` John Mackin
  1991-08-24 15:10     ` Severe egg on face John Mackin
  0 siblings, 1 reply; 4+ messages in thread
From: John Mackin @ 1991-08-24  3:48 UTC (permalink / raw)
  To: The rc Mailing List

I wrote:

    eval `{ whatis | rev | sed -n -e '/ nf$/s/^.*{\(.*\)$/\1/p' | rev }

    You can't really do without the two rev's, [...]

Apologies to all on the list, I must've been drunk :).  Sheesh, do I
feel like a silly person; the above, of course, _still_ doesn't work
in the presence of function names containing {.  Anyway it can be done,
but I don't have time now to fully test an implementation, and rather
than mail another implementation that isn't fully tested, I'll just
describe how to write the sed:

- any line beginning with "fn " either does or doesn't begin with "fn '"
- if it doesn't, then the function name terminates at the second
  space character on the line
- if it does, then the function name terminates at the first "'" character
  following the "'" character in "fn '" which is not preceded by a "'"
  (wow, thank Duff for rc's simple, consistent quoting rules!)

And you don't need any rev's, just the sed.

Hangs head in shame....

OK,
John.



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

* Severe egg on face
  1991-08-24  3:48   ` John Mackin
@ 1991-08-24 15:10     ` John Mackin
  0 siblings, 0 replies; 4+ messages in thread
From: John Mackin @ 1991-08-24 15:10 UTC (permalink / raw)
  To: The rc Mailing List

_This_ time, I wrote:

    - if it does, then the function name terminates at the first "'" character
      following the "'" character in "fn '" which is not preceded by a "'"
      (wow, thank Duff for rc's simple, consistent quoting rules!)

Heavy sighing is about all I can manage at this stage.  Of course,
this breaks in the simple degenerate case of a function named '.

I'm now pretty certain (although having been this stupid, I don't
feel too certain about anything :() that this can't be done with
grep-style regular expressions, and therefore can't be done with sed.
If anyone is interested in following that up, do let me know if
you succeed: the problem is that when you match a ', it's not a terminator
if it was preceded by [^']', but is one if it was preceded by ''
or [^'], and I don't think it's possible to express that in a grep RE.
I _believe_ it can be done with an egrep RE, and therefore the
task can be accomplished with awk -- but I am by no means
prepared to assert that definitely.  (Being wrong does terrible
things to my self-confidence.)

As a sop, I'm prepared to offer the thought that all this doesn't
matter that much, since the purpose of getting rid of functions
with -p is to prevent people `surprising' your script, and for
that purpose, functions with quoted names aren't going to matter
and could be ignored (and left in the environment).  This is
by no means _right_, though.  If it can't be done with awk,
the solution is to code it up in C...

OK,
John.


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

end of thread, other threads:[~1991-08-24 15:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-08-23 20:47 early reaction(s) to rc Arnold D. Robbins
1991-08-24  0:15 ` John Mackin
1991-08-24  3:48   ` John Mackin
1991-08-24 15:10     ` Severe egg on face John Mackin

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