有没有办法在不运行 ~/.bashrc 脚本的情况下打开 Windows 10 Ubuntu bash?

iii*_*iii 15 command-line bash bashrc windows-10 windows-subsystem-for-linux

我正在 Windows 10 Ubuntu Bash 中编辑 bashrc 脚本,但在编辑脚本时出错。现在 bash 在打开它时立即退出。有没有办法让我在不运行 bashrc 的情况下打开 Bash,或者我必须重新安装它?

ste*_*ver 24

您应该能够以.bashrc与“常规”bash 中基本相同的方式跳过在 WSL 中加载默认文件:

  --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.
Run Code Online (Sandbox Code Playgroud)

因此,打开 WindowsCMD.exe并键入

wsl.exe -e bash --norc
Run Code Online (Sandbox Code Playgroud)

进入交互式 shell 后,您可以恢复对~/.bashrc文件所做的更改。

  • @jpmc26 - 因为在这种情况下,这并不重要,两者都可以工作并且结果完全相同,但是 cmd 加载速度更快,并且更容易使用纯键盘命令打开 (5认同)