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
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
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
Use –noprofile –norc:
--noprofile 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
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 cd
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.
$ env -i HOME=$(mktemp -d) bash --noprofile --norc bash-5.0$ cd bash-5.0$ pwd /tmp/tmp.mwgHRQE1aJ bash-5.0$ printenv PWD=/tmp/tmp.mwgHRQE1aJ HOME=/tmp/tmp.mwgHRQE1aJ SHLVL=1 OLDPWD=/home/xxxxxxxxxxxxxxxxx _=/usr/bin/printenv bash-5.0$
Answered by Pierre D
Post is based on https://stackoverflow.com/questions/9357464/how-to-start-a-shell-without-any-user-configuration