Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an easy way to isolate a session of bash so that only essential variables (HOME, USER, DISPLAY, etc.) are preserved? (essential in that many programs fail if HOME, DISPLAY, TERM, SHELL, etc. are not set). Namely, does anyone know where these are set?

I had tried adding the line test -n "${NO_ALIASES+D}" && return 0 to my ~/.bash_aliases (I didn't do anything additional in ~/.bashrc) so a pristine ~/.bashrc would be sourced if I did

env -i NO_ALIASES=1 bash

but those variables were still missing.

I also tried source /etc/profile too in the isolated shell, but to no avail.

The one that does work is a manual pass-through:

share|improve this question
What exactly do you want to do? Why do you need this? Which variables do you not want? – terdon Feb 9 '14 at 18:16
I want to work within the same user account but with the minimal set of environment variables, without having to manually switch around my environment itself. I am working with ROS's catkin build system, which is an awesome tool (for doing stuff like cohesive workspaces and multiple builds, chaining workspace dependencies, path management). Within this system and ROS itself, there are a ton of environment variables, a lot of which are appended to, and some that may not go away by re-sourcing the setup files. I would like to reproduce results by isolating the env. – eacousineau Feb 9 '14 at 22:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.