2012-02-20 47 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

相關問題