0

My Terminal Image:

enter image description here

enter image description here

I'm using Ubuntu with WSL and can't access GUI.

Aforementioned images of my terminal, no output is displaying for anything I type. Terminal is acting like an editor. It happened after I edited PS1 variable. I want to revert this action.

M11
  • 11
  • 2

2 Answers2

2

Glad you were able to break out of it. In the future, since you are using WSL, keep in mind that you also have the following options for recovering.

From PowerShell, CMD, or the Start menu:

wsl -e bash --norc --noprofile

This will start WSL and execute Bash without processing any startup files such as ~/.bashrc (and others). From there, you can inspect and fix any startup files or other problems. This is typically the best recovery mechanism for this type of problem.

You can even edit your .bashrc directly without starting your shell with:

wsl -d Ubuntu20.04_WSL2 -e editor /home/<username>/.bashrc

Note: The editor command maps to the "preferred editor" on Ubuntu (nano by default). On some other distributions, you may need to specify the editor name itself (e.g. vi). You can change the default editor with sudo update-alternatives --config editor.

Finally:

wsl -u root

This will access WSL as the root user, where you may then edit your user files. Note that if there's an error in /etc/profile (or the .d subdirs) then this still won't work, as the root user will experience the same error. That's why I tend to prefer the --noprofile --norc option.

Also, from the comments:

I'm not able to open the bashrc

Two options there:

  • As @terdon mentioned in the comments, you could at least view the file by using File Explorer in Windows to navigate to \\wsl$\Ubuntu\home\<username>\ (or the distro name you are using, it may have a version number).

    Note that I don't recommend editing the file using a Windows application unless you are sure that the application will respect Linux/Unix line-endings. Some applications (older versions of Notepad, for instance) will "corrupt" the file (at least from Bash's perspective) by changing line-endings to DOS/Windows CRLFs.

  • Or, from PowerShell:

    wsl -e cat /home/<username>/.bashrc | clip.exe
    

    That will copy it directly to the clipboard so that you can paste any relevant portions into your question next time.

Please don't post images of text. Just copy/paste the text directly into your question

It's also possible to just highlight the text directly in the terminal that you put in the screenshot and paste it into the question.

I would still ask that you do this (if you haven't fully fixed the error yet), as it may help others find your question when searching the web. Images, of course, aren't often indexed. See here for additional reasons why we ask that you avoid screenshots when text will suffice.

NotTheDr01ds
  • 22,082
-1

Pressing Ctr+C will resolve the issue.

M11
  • 11
  • 2