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
  • Does this answer your question? How to restore .bashrc file? – Artur Meinild Sep 08 '22 at 09:56
  • Please don't post images of text. Just copy/paste the text directly into your question and use the {} button to mark it as code. If you [edit] your question and show us the contents of your .bashrc, we can help you fix it. – terdon Sep 08 '22 at 09:59
  • @terdon I'm not able to open the bashrc. My terminal is acting like an editor. Whatsoever I type nothing pops, I tried exit command even it didn't work.. – M11 Sep 08 '22 at 10:03
  • You have probably left an open quote somewhere. Does pressing Ctrl+C help? Can't you access .bashrc from Windows itself somehow? – terdon Sep 08 '22 at 10:06
  • @terdon mucho gracias,, it worked. I think their is some task running in the background, dapping CTRL+C thwarted it.. Tnx bro/sis – M11 Sep 08 '22 at 10:09
  • Great! Do you still need help restoring your bashrc? If you post it here we can help. – terdon Sep 08 '22 at 10:10
  • @terdon, I had added source ~/.bashrc in the ~/.bashrc file. And I need help on how to customize the the prompt. E.g m11@m11:<here I want the output of pwd command> – M11 Sep 08 '22 at 10:19
  • OK. Remove the source command, that enters an infinite loop. And please post a new question about PS1 or just Google it since that is a very basic addition and you will find loads of resources. – terdon Sep 08 '22 at 11:13

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
  • 17,888
-1

Pressing Ctr+C will resolve the issue.

M11
  • 11