15

I was editing the bashrc script in my Windows 10 Ubuntu Bash and I made a mistake while editing the script. Now bash exits immediately upon opening it. Is there a way for me to open Bash without running bashrc, or will I have to reinstall it?

3
  • 2
    Why not just edit .bashrc from any Windows App such as Notepad++ ? Jul 8, 2019 at 13:12
  • 4
    @CarlWitthoft I believe you can't (shouldn't?) edit WSL files from Windows (but you can do it the other way around).
    – Martin
    Jul 8, 2019 at 14:29
  • I believe that it is safe to rename WSL files from Windows — so just rename .bashrc to .bashrc.hold. Or is that dangerous too? Jul 8, 2019 at 15:29

2 Answers 2

25

You should be able to skip loading the default .bashrc file in WSL in essentially the same way as in "regular" bash:

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

So, open the Windows CMD.exe and type

wsl.exe -e bash --norc

Once you are in the interactive shell you can revert the changes yo made to the ~/.bashrc file.

3
  • CMD? Why not PowerShell? Not perfect, but way better than cmd.
    – jpmc26
    Jul 8, 2019 at 15:06
  • 5
    @jpmc26 - Because in this situation, it doesn't matter, both work and the result is the exact same, but cmd is faster to load and easier to open with purely keyboard commands
    – Taegost
    Jul 8, 2019 at 15:46
  • 1
    There's no need to open a prompt first at all, you can simply hit the windows key and type "wsl -e bash --norc" followed by enter. Jul 8, 2019 at 19:55
0

I have more than one distro on my wsl. The faulty one was not the first I installed, so not the default. In order to apply the above solution, we have first to set the faulty distro to be the default, so the invoked bash will be then used.

wsl --set-default --set-default Ubuntu-20.04

So then, the command

wsl.exe -e bash --norc

will invoke the right bash.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .