Closed svend closed 9 years ago
I think this can't reliably be done, for the same reason that the existing code avoids calling env
to print out all the environment variables: their values are allowed to contain "=", "\n" and other characters which would make the env
output irregular. The existing code makes sure to print them surrounded by nulls, but there's no way to tell env
to just list the names of the environment variables it knows about.
If you're aware of a way to make any POSIX-compliant shell enumerate all its exported environment variables, then it may be possible to do this.
Good point. I don't know a POSIX way to do this.
GNU printenv and env support --null
, but the OS X versions do not. I can get a list using gprintenv from homebrew coreutils on OS X like this:
(mapcar (lambda (s) (car (split-string s "=")))
(split-string
(shell-command-to-string "bash -l -i -c \"gprintenv --null\" 2>/dev/null")
(char-to-string ?\x0)
t))
Good to know. I really want to avoid relying on anything that won't necessarily be available on every UNIX, though. Compatibility across zsh
, bash
, tcsh
and fish
has already been surprisingly hard to achieve.
Agreed. I don't have a good solution, so I'll close this.
It would be convenient to be able to copy all environment variables without specifying them individually. Could the list of environment variables be obtained by parsing the output of
env
?