1

Distro: Ubuntu-18.04 (running on Windows 10 WSL2)

My terminal for any new Ubuntu instance is completely frozen with the message "Vim: Warning: Output is not to a terminal"

This happened after editing the .bashrc file on VIM where all I did was add in an alias for some ls command. Once I entered source .bashrc, the above message showed up. I am unable to ctrl+C or ctrl+z my out of anything and no prompts show up to allow for any command typing.

screenshotOfTerminal_"Vim: Warning: Output is not to a terminal"

It's almost certain I made some sort of mistake while editing the .bashrc file but I'm unable to even view that file, let alone edit and execute it. Any way to fix this issue other than reinstalling the whole distro?

Edit 1: I'm able to see the bashrc file through Windows File Explorer. Here is a portion of it:

enter image description here

The only part that I edited was adding a new alias called starship, so just this part:

alias starship='vi ~/.config/starship.toml'

Looks like correct syntax to me, so now I'm even more confused why this issue is happening.

Edit 2: The terminal hanging just stopped after a while and now I'm able to do work on the terminal again. I didn't really do anything to it, just waited. My guess the issue had nothing to do with the alias addition and was something to do with Starship prompt program.

Edit 3: Answer given by NotTheDr01ds perfectly solved the issue. And as brought up by muru, the alias most definitely caused the issue in the first place, where I overrode the command eval "$(starship init bash)" (at the bottom of the bashrc file) as a result of the new alias called starship.

2
  • If you've resolved your issue, you should answer it as well. This closes the question so it doesn't show up as "unresolved" down the line. Advice how to formulate a good answer is here Feb 14 at 7:31
  • "was something to do with Starship prompt program" ... does that mean there's a starship command that's used for your prompt, and you created a starship alias that overrides that command to run vi instead?
    – muru
    Feb 14 at 7:48

1 Answer 1

1

This appears to me to be expected behavior. While your most recent edit says that you regained control over the terminal, my guess is that the error will reappear the next time you start WSL.

Here's what's happening:

  • When you install Starship, it tells you to add the following line at the bottom of your ~/.bashrc:

    eval "$(starship init bash)"
    
  • You then redefined the starship command as an alias in Bash above that with:

    alias starship='vi ~/.config/starship.toml'
    

Result:

The last line in your ~/.bashrc is interpreted as:

eval "$(vi ~/.config/starship.toml init bash)"

If you enter that line, you'll see the same error message, and the terminal will hang again. What's happening is that vi is running in a Bash command substitution. This is a subshell that is not interactive, and thus does not have a terminal attached to it. Standard output (et. al.) does not go to the screen, but instead is captured to be interpreted (eval'd) by the shell.

So vi is running as soon as you source your ~/.bashrc (or restart your shell). Knowing this, you can likely recover from it with something like:

Ctrl+C Ctrl+C :qEnter:q

That's basically trying to get Vim back into a state where it can accept a "quit" command (:q). Even though you can't see what's happening, Vim is still processing the keys.

Another way to recover would be to start a new PowerShell terminal, then run:

wsl ~ -e bash --noprofile --norc

That will start WSL (and Bash) without processing the problematic ~/.bashrc, allowing you to ps auxw, kill the offending vi process, and then edit your ~/.bashrc to fix the problem.

You have (at least) three potential fixes:

  • Recommended: Get rid of the alias entirely. You'll find that aliases like this aren't that useful, as you won't edit that file all that often anyway. And there are literally dozens (if not hundreds) of configuration files you'll need to edit when using Linux, so it just doesn't make much sense to set up an alias for each of them.

  • If you want to keep the alias, rename it so that it doesn't clash with an existing command edit_my_prompt or something like that.

  • Or, change the last line (that invokes Starship) to be:

    eval "$(command starship init bash)"
    

    Putting command before a command will cause it to ignore the alias and call the actual starship command as intended. Also see Run a command that is shadowed by an alias.

You must log in to answer this question.

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