I set a variable with spaces in a string to a new bash:
VAR='my variable with spaces' /bin/bash
And now if I want to start a new bash with the same environment, I would do something like:
ENV=$(cat /proc/self/environ | xargs -0 | grep =)
env -i - $ENV /bin/bash
But the thing is, in /proc/self/environ, this variable is without quotes. So the last command throws a: env: variable: No such file or directory
How can I work around this limitation?
PS: this is a simplified version of the following issue: https://github.com/jpetazzo/nsenter/issues/62
I think the answer here is to not use a shell script to set things up. Using a higher-level language makes it much easier to parse
/proc/<PID>/environinto something useful. Here's a short example:Put this in a file called
env-from, make it executable, and then you can run:And you'll get a shell using the environment variables from the specified process.