Coder Perfect

How do you launch a shell without any user settings?


I need to use a “clean” shell (e.g. bash) without any user settings on a Linux/OSX terminal, but it receives config information from some files (e.g. /.bashrc) every time it starts. I can alter the file whenever I need a “clean” shell and revert it when I’m done, but are there any other options, such as a command?

Asked by lil

Solution #1

The parent process is still inherited when using bash —noprofile —norc. I discovered that the way I interpreted this question, env -i bash —norc —noprofile, was exactly what I wanted based on a previous inquiry.

Answered by nnutter

Solution #2

The —noprofile and —norc command-line parameters can be used:

$ bash --noprofile --norc

You will find documentation about these options in the man page.

Answered by Frédéric Hamidi

Solution #3

Use –noprofile –norc:

          Do  not  read either the system-wide startup file /etc/profile or any of the personal initializa‐
          tion files ~/.bash_profile, ~/.bash_login, or ~/.profile.  By default,  bash  reads  these  files
          when it is invoked as a login shell (see INVOCATION below).

   --norc Do  not  read  and  execute the system wide initialization file /etc/bash.bashrc and the personal
          initialization file ~/.bashrc if the shell is interactive.  This option is on by default  if  the
          shell is invoked as sh.

(from the manpage).

Answered by user unknown

Solution #4

It’s common to want to start with a clean slate:

This works on both MacOS and Linux for me:

env -i HOME=$(mktemp -d) bash --noprofile --norc

The HOME dir in that bash shell is the test dir you just created (alter the name if necessary), and there are no special settings. PWD, HOME, and SHLVL are the only environment variables that have been set.

The PWD is where we were before we started bash, thus we need to do that first cd.

Example (Linux):

$ env -i HOME=$(mktemp -d) bash --noprofile --norc
bash-5.0$ cd
bash-5.0$ pwd
bash-5.0$ printenv

Answered by Pierre D

Post is based on