I need to save environment variables to a file and (later) a process should import them. I need this to workaround a program
fooprog that nullifies the environment before executing a
barscript, and I need some environment variables in
barscript. So I'm planning on saving all environment variables to a file before executing
fooprogram, and make
barscript source them from a file.
I tried this, but it doesn't work if there are variables that contain spaces.
$ env > my_environment $ . my_environment
I guess the correct way is to fiddle with
/proc/$$/environ and parsing this from
barscript somehow, but I can't find the correct way of doing that.
edit: Quotes or newlines are problematic too. How could it be done so that envars as problematic as the following could be sourced without problems?
PROBLEMATIC='this has double quotes " and single quotes '\'' and even newlines. See?'