rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Question about input redirection in -c
@ 1993-08-13 15:47 Stefan Dalibor
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Dalibor @ 1993-08-13 15:47 UTC (permalink / raw)
  To: rc-owner


Hi,

from the manpage:

  -c   If -c  is  present,  commands  are  executed  from  the
       immediately  following argument.  Any further arguments
       to rc are placed in $*.

and:

  exec [arg ...]
       Replaces rc with the given command.  If the  exec  con-
       tains  only redirections, then these redirections apply
       to the current shell and the shell does not exit.   For
       example,

            exec >[2] err.out

       places further output to standard  error  in  the  file
       err.out.

this made me think

  rc -c 'pwd; . /dev/tty'

would have the same effect as 

  rc -c 'pwd; exec </dev/tty'

But it has not - the first command behaves as expected (execute pwd,
then read from the terminal), the second executes pwd, but the input
redirection is ignored and rc exits.
Browsing through the source code revealed that the redirection *is*
done (doredirs() is called in exec()), but is ignored in doit() after
returning from walk() - the EOF the lexer got from parsing the
argument string `overrides' the input redirection because no pushfd()
is performed. 

A comment in doit() (`` "last" can be clobbered during a walk() '')
and comparisons with other shells indicate that rc does this on 
purpose - but I can't see the reason for it. For me it's puzzling that
`exec</dev/tty' changes its meaning when executed via `rc -c', so
could some kind soul please explain it?

Bye,
Stefan

--                                                                  --
Stefan Dalibor                dalibor@immd3.informatik.uni-erlangen.de


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

* Re: Question about input redirection in -c
@ 1993-08-18  7:47 Stefan Dalibor
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Dalibor @ 1993-08-18  7:47 UTC (permalink / raw)
  To: rc-owner


> I.e., you are conflating "stdin" with "the place rc reads commands
> from".

Yes, thanks - I was indeed under the impression that `<' would do
input source redirection, not just file-descriptor manipulation.
In the end, it turned out to be easy (like most things with rc):
  rc -c 'pwd; exec <0=]; . -i /dev/tty'
does what I want (use readline() when sourcing the tty). 

Some memory nitpicking: Purify suggested the following changes to
input.c; the first hunk avoids a memory leak when using rc with
readline (the documentation for GNU-readline says that the strings
returned by readline() should be freed if no longer needed), the
second prevents accessing uninitialized memory (as istack's
fd-component isn't initialized by pushstring()). The diffs are against
plain rc-1.4. Purify detected a few other minor memory leaks, but I
leave it to the author to plug them in the next release, as promised
in an earlier message :).

Stefan

*** rc-1.4/input.c	Fri Dec 11 10:21:17 1992
--- input.c	Tue Aug 17 17:04:51 1993
***************
*** 129,132 ****
--- 129,133 ----
  					strcpy(inbuf+2, rlinebuf);
  					strcat(inbuf+2, "\n");
+ 					efree(rlinebuf);
  				}
  			} else
***************
*** 214,222 ****
  	efree(inbuf);
  	--istack;
! 	realgchar = (istack->t == iString ? stringgchar : fdgchar);
! 	if (istack->fd == -1) { /* top of input stack */
  		realgchar = dead;
  		realugchar = ugdead;
  	}
  	last = istack->last;
  	eofread = istack->eofread;
--- 215,226 ----
  	efree(inbuf);
  	--istack;
! 	if(istack->t == iString)
! 		realgchar = stringgchar;
! 	else if (istack->fd == -1) { /* top of input stack */
  		realgchar = dead;
  		realugchar = ugdead;
  	}
+ 	else
+ 		realgchar = fdgchar;
  	last = istack->last;
  	eofread = istack->eofread;


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

* Re:  Question about input redirection in -c
@ 1993-08-13 21:17 Byron Rakitzis
  0 siblings, 0 replies; 3+ messages in thread
From: Byron Rakitzis @ 1993-08-13 21:17 UTC (permalink / raw)
  To: dalibor, rc-owner

exec</dev/tty replaces the shell stdin with /dev/tty, however

	rc -c cmd

makes rc read commands from the string "cmd", NOT from stdin. Therefore
it is irrelevant to rc's parser how you choose to manipulate fd0 in this
case.

I.e., you are conflating "stdin" with "the place rc reads commands from".


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

end of thread, other threads:[~1993-08-18 16:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-08-13 15:47 Question about input redirection in -c Stefan Dalibor
1993-08-13 21:17 Byron Rakitzis
1993-08-18  7:47 Stefan Dalibor

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