setenv from c

der Mouse mouse at mcgill-vision.UUCP
Wed Oct 9 17:24:35 AEST 1985

> >> Is it possible to set a csh environment variable within a C program?
> >
> >In all the replies to this question, I have not yet seen my favorite techniqe.
> >This only works on BSD 4.X (at least as far as I know).  There is an
> >undocumented ioctl() which allows you to push data back onto your input queue
> >(i.e. simulate characters typed at the terminal).  Using this technique, one
> >can stuff strings like "setenv TERM xxx\n" into the parent shell's input.
> >
[[[ code using TIOCSTI omitted ]]]
> Undocumented? TTY(4) page 12 (66lines/page).  This call does not exist
> on either System 5 or Version 7 - however the hack to put them into the
> kernel is about twenty lines.  Oh for this and FIONREAD to be put into
> standard SYS V!!!

     How right you are.  TIOCSTI is one of  the neatest features around.
(Maybe not heavily used, but neat.)  However, I must take issue with

> > Using this technique, one can stuff strings like "setenv TERM xxx\n"
> > into the parent shell's input.

     You can't, in general.  All you can do is stuff stuff back into the
terminal  input stream, which is not always  the  shell's  input  stream
(shell scripts etc).  Besides, guess what it can do to typeahead:

	login: mouse

	Last login etc....
	/etc/motd etc....

	cd foo
	% % setenv TEaRM xxx
	emsetenv: Command not found.
	% cs test.c
	cs: Command not found.

     Well, maybe I notice in time not to hit the last newline.  Besides,
that isn't  what  it looks like because I hacked  upon my  shell to give
supersmart line editing (and I don't use "%" for my prompt).

     Tsk  tsk.    Please  try  to  be  more  precise  in  the  future.  
<admonishing frown, and in case someone didn't notice, (:-)>
					der Mouse


Hacker: One responsible for destroying /
Wizard: One responsible for recovering it afterward

More information about the Comp.lang.c mailing list