【问题标题】:How to start a shell without any user configuration?如何在没有任何用户配置的情况下启动 shell?
【发布时间】:2012-03-10 13:51:14
【问题描述】:

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

【问题讨论】:

  • 下面提供的答案也很有用,例如,当一个人在他们的.bashrc.bash_profile 文件中犯了一个错误,导致 shell 过早退出。

标签: linux macos bash shell


【解决方案1】:

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

【讨论】:

  • 感谢env -i 提示!这对我来说有点干净了,因为我只是想摆脱我的自定义设置,但我仍然需要系统范围的设置。这就是我最终使用的:env -i bash --rcfile /etc/profile
  • 很棒的提示。 “env -i”正是我所需要的。尽管有“--noprofile --norc”,但我的 bash_profile 仍在被读取。
  • 您不需要参数 --noprofile 因为它仅在您有登录 shell 时才相关。
  • 它仍然继承history
  • env -i bash --norc --noprofilebash --norc --noprofile有什么区别?
【解决方案2】:

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

$ bash --noprofile --norc

您可以在man page 中找到有关这些选项的文档。

【讨论】:

  • bash --noprofile --norc 仍然继承自父进程。
  • 这对我来说已经足够好了。摆脱了我的别名、提示等。
【解决方案3】:

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

(来自手册页)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    • 2015-12-09
    • 1970-01-01
    相关资源
    最近更新 更多