You can inherit the environment variables from PID 1 by iterating over the list of null-terminated strings
in /proc/1/environ
, parsing the first characters up to the first =
as the variable name, setting the
remaining value as that variable, and exporting it.
The Code Snippet
This works with multiline environment variables, and environment variables with arbitrary values, like
strings, including =
or JSON blobs.
Paste this in your current terminal session to inherit the environment variables from PID 1: