Setenv from C
COTTRELL, JAMES
cottrell at nbs-vms.ARPA
Wed Sep 25 04:41:34 AEST 1985
/*
> 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.
In a word NO! There is no way to affect your parent's environment unless
they made prior arrangements (like before you were born) to do so.
Sounds kinda like Life, doesn't it?
A way to do this is to set up an alias which runs your program,
then sources a file which the program builds. Try the following:
alias z 'echo setenv QAZ WSX > EDC ; source EDC'
Now type `printenv;z;printenv'. Note the change!
Another method might be:
setenv NAME `prog`
if you only want you change ONE variable & you know it's name. If you
want to change more, you can always do:
set x = `prog` ; $x
I don't know why `prog` by itself on a line doesn't work. Probably
because `...` only returns one word. Oh well...
jim cottrell at nbs
*/
------
More information about the Comp.lang.c
mailing list