I am a frequent answerer on a Unix-focused popular Q&A site, and in many of my answers I provide examples using the bash
shell. However, each time I do this I have to manually go through the process of creating a clean environment to make sure that every step is accounted for and documented. How can I make this process more straightforward? I am ideally looking to type a single command and get a clean environment, and have all traces of that temporary environment removed after I am done.
Bash – How to create a clean shell environment for temporary use
bashenvironment-variablesprofile
Best Answer
I personally use the following
bash
function to do this:Here is what it does, in order:
bash
rc file);PS1
prompt to the prompt terminator followed by a space, which keeps it relevant in case we want to have a copy of our output on the Q&A site;bash
, which:$HOME
and$TERM
(env - ...
);--rcfile
).Obviously this is not totally foolproof, that is, you can still access other parts of your system. This does, however, provide a clean temporary environment which you can use for testing.