[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: updating shell environment variables
From: |
Pascal Bourguignon |
Subject: |
Re: updating shell environment variables |
Date: |
05 Nov 2004 20:27:52 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
"Dan Elliott" <dan_elliott_at_cox_dot_net@noSpam.org> writes:
> Kevin Rodgers wrote:
> > I guess `C-h a env RET' was too painful to even try.
I prefer to write: M-x apropos RET env RET
> My intended question is a bit more complicated. Change the above from "few"
> to "nearly one-hundred." I have failed to discover an effective way to do
> this. Can I somehow *flash* the state of emacs' environment variables to be
> in line with the shell that "owns" my current emacs session?
All emacs _commands_ are _functions_ too.
M-x setenv RET variable RET value RET <==> (setenv variable value) in a .el
Depending on how you store your nearly one-hundred variable/value,
you can write a loop to iteratively setenv them.
The fundamental mechanism of environment variables is that each
process has its onw set, there's no sharing. When a process forks a
child, all its environment variables are _copied_ into the child
process, which inherit the same values, and that is the ONLY automatic
mechanism of communication of environment variables.
Once forked, the processes are entirely independent with respect to
their environment variables.
Now, you seem to be changing the environment variables in one process
(a shell) (it does not matter whether it's the parent or a stranger
process), and want to get the same environment into another process
(your emacs).
>From a shell you can easily collect the environment with the env(1)
command. Once again, was it so difficult to use apropos(1)?
Perhaps you'll get a hint at some pattern here:
M-x apropos RET env RET in emacs
apropos env RET in shell
For example, you can put the current environment variables into a file:
$ env > ~/current-environment
Then you can easily enough read this file from emacs, parse it and
setenv. Perhaps you want to remove environment variables that are not
present in the imported environment. Unfortunately, it seems that it's
not possible to gather the list of all environment variables from
elisp. You'd have to modify the source of emacs, or launch it from a
wrapper to know the original list of environment variables.
There may be problems if some environment values contain some NEWLINE,
then you'd have to write your own environment dumping program. By the
way, it may be easier to write a small C program that will dump the
environment variable directly as an elisp source containing lines of:
(setenv "var" "val")
that you would just load from emacs. (No need to parse, just to escape
correcly the variables and the values strings).
--
__Pascal Bourguignon__
Re: updating shell environment variables, Thien-Thi Nguyen, 2004/11/05