2012-02-20 66 views
20

我需要在Linux/OSX终端下使用“clean”shell(例如bash),而无需任何用户配置,但每次启动时都会从某些文件(例如〜/ .bashrc)读取配置信息。每次我需要一个“干净”的shell时,我都可以修改这个文件,并在完成后恢复它,但是有没有更简单的方法来执行此操作,例如命令?如何在没有任何用户配置的情况下启动shell?

+1

题外话;属于[su] – 2012-02-20 07:20:26

+1

或Unix&Linux。 – 2012-02-20 23:00:38

回答

10

您可以通过--noprofile--norc命令行选项:

$ bash --noprofile --norc 

,可以找到关于在man page这些选项的文档。

+4

'bash --noprofile --norc'仍然继承父进程。 – nnutter 2015-10-18 18:24:37

+1

这对我来说已经够好了。摆脱了我的别名,提示等。 – wisbucky 2017-09-15 22:33:47

2

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

(从手册页)。

31

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

+2

感谢'env -i'提示!这样做对我来说有点*太干净了,因为我只是想摆脱我的自定义设置,但我仍然需要系统范围的设置。这就是我最终使用的:'env -i bash --rcfile/etc/profile' – DaoWen 2015-07-17 18:49:01

+0

伟大的提示。 “env -i”正是我所需要的。尽管有“--noprofile --norc”,我的bash_profile仍在读入。 – 2017-01-24 19:55:15

+0

您不需要参数--noprofile,因为它只与您有登录shell有关。 – Chad 2017-05-21 08:07:54

相关问题