Artificial intelligent assistant

How do I reliably convert /proc/pid/environ to arguments for the env command? How do I reliable convert /proc/pid/environ to argument for the env command? * `IFS=$'\n' ; env -i $(xargs -0n1 -a /proc/$$/environ)` only works when all environment variables do not have the newline character. * `IFS=$'\0'`is not working in bash and dash. Is there any other available way (included any other shell way)?

In bash, you can create an array from entries in the `environ` file, and use the array elements as arguments to `env`:


mapfile -d '' envs < /proc/$$/environ
env -i "${envs[@]}" ...


It seems to work fine with newlines:


$ foo=$'a\
b' bash
$ mapfile -d '' envs < /proc/$$/environ
$ printf '|%s|\
' "${envs[@]}"
|foo=a
b|
|LC_MEASUREMENT=en_GB.UTF-8|
|SSH_CONNECTION=127.0.0.1 33066 127.0.0.1 22|
...

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy a4f8f6c8b58ac6e1eb6fe58f9d26a42e