Linux 如何在没有任何用户配置的情况下启动 shell?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9357464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:40:58  来源:igfitidea点击:

How to start a shell without any user configuration?

linuxmacosbashshell

提问by lil

I need to use a "clean" shell (e.g. bash) under Linux/OSX terminal without any user configuration, but it reads config info from some files (e.g ~/.bashrc) every time it starts. I can modify the file every time I need a "clean" shell, and revert it back when I finished, but is there any easier ways to do this, for example a command?

我需要在没有任何用户配置的情况下在 Linux/OSX 终端下使用“干净”的 shell(例如 bash),但它每次启动时都会从某些文件(例如 ~/.bashrc)中读取配置信息。每次我需要一个“干净”的外壳时,我都可以修改文件,并在我完成后将其还原,但是有没有更简单的方法来做到这一点,例如命令?

采纳答案by Frédéric Hamidi

You can pass the --noprofileand --norccommand-line options:

您可以传递--noprofile--norc命令行选项:

$ bash --noprofile --norc

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

您将在手册页中找到有关这些选项的文档。

回答by user unknown

Use --noprofile --norc:

使用 --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).

(来自联机帮助页)。

回答by nnutter

Running bash --noprofile --norcstill inherited from parent process. Based on a similar questionI found that the way I interpreted this question env -i bash --norc --noprofilewas what I would want.

运行bash --noprofile --norc仍然继承自父进程。基于一个类似的问题,我发现我解释这个问题的方式env -i bash --norc --noprofile正是我想要的。