Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site mips.UUCP
Path: utzoo!linus!decvax!decwrl!Glacier!mips!mash
From: mash@mips.UUCP (John Mashey)
Newsgroups: net.lang.c
Subject: Re: setenv from c
Message-ID: <196@mips.UUCP>
Date: Mon, 23-Sep-85 00:25:23 EDT
Article-I.D.: mips.196
Posted: Mon Sep 23 00:25:23 1985
Date-Received: Wed, 25-Sep-85 11:51:11 EDT
References: <2936@ncsu.UUCP>
Organization: MIPS Computer Systems, Mountain View, CA
Lines: 29

Rick Johnson (decvax!mcnc!ncsu!rlj) writes:
> Is it possible to set a csh environment variable within a C program? I know
> about getenv(), but have failed at attempts to set an environment variable
> from a C program. Basically, what I want to do is "source" a new environment
> variable for the current csh process. Any comments or suggestions would be
> appreciated. Thanks.

I assume that you're not interested in just modifying the current environment,
[which is fairly straightforward, and has been posted somewhere in last
6 months], but in getting changes back to the parent shell [csh or sh].

You can't modify the parent shell's environment directly, but only by
returning a character string to be "eval"ed.  Suppose C pgm "glurp" ends with:
	printf("setenv a b\n"); 
Invoke it with: 	eval `glurp`
to set a = b.  More complex effects can be gotten by changing the printf string.

A process cannot modify its parent's environment, on purpose.  At one point,
such a feature was considered, and rejected, because it had no simple,
understandable semantics.  For example, many otherwise deterministic
computations turn nondeterministic, depending on process scheduling.
Consider a pipeline like a | b | c, where all of a, b, c could modify
their parent's environment, or worse, nohup a& (and logoff).  [Exactly
what is a modifying?]
-- 
-john mashey
UUCP: 	{decvax,ucbvax,ihnp4}!decwrl!mips!mash
DDD:  	415-960-1200
USPS: 	MIPS Computer Systems, 1330 Charleston Rd, Mtn View, CA 94043