How to change default shell for Linux susbsystem for Windows

10

3

I've installed Linux subsystem for Windows 10. It works fine, but I want to change the default shell environment for the subsystem.

I did sudo apt-get install fish and then chsh -s /usr/bin/fish. But when I start bash.exe in Windows, it always starts the bash (I think it is predictable).

Does anyone know arguments to change this behavior?

Envy

Posted 2016-08-07T19:08:29.733

Reputation: 163

When you start bash.exe you are obviously explicitly starting bash. I'm not familiar with the Linux subsystem in Windows 10, but I would expect there to be some way to start a "Linux" shell without explicitly starting one specific shell. – a CVn – 2016-08-07T19:25:43.163

Did you tried an ugly edition of your bashrc or bashprofile to re-route interactive bash calls to fish? Adding a line like isatty && exec fish may worth the try when you are totally out of actual solutions. – A. Loiseau – 2016-08-07T22:52:32.090

Answers

6

You cannot change the default shell per se since the Linux subsystem is started via the bash.exe residing in the system directory.

You can, however, make a new shortcut like the one that already exists for bash and make it run the command

%systemroot%\system32\bash -c /usr/bin/fish

This way you will be running fish immediately.

Sami Kuhmonen

Posted 2016-08-07T19:08:29.733

Reputation: 2 052

1I used %systemroot%\system32\bash.exe ~ -c /bin/zsh to make ZSH open in my home directory. – David Pärsson – 2016-08-11T20:13:31.783

Alternatively, set the "Start in" field in the shortcut to %userprofile% to start the shell in your home directory. – dOxxx – 2016-09-29T02:07:48.227

@konqui This doesn’t break any other shell. It’s a new shortcut for starting it. Your bash will work just fine – Sami Kuhmonen – 2017-11-01T07:49:18.550

@SamiKuhmonen there wasn‘t anything said about a new shortcuts - i corrected it now i can life with this answer. – konqui – 2017-11-01T07:54:01.643

9

Since Fall Creators Update you can use chsh to setting default shell. This still doesn't work if you are running WSL using bash.exe command but this work if you running WSL with ubuntu.exe command.

Also, since Fall Creators Update we should to install WSL OS from Windows Store.

Set zsh as default shell:

chsh -s /bin/zsh

then run (or restart) ubuntu.exe from command prompt.

Mikhail

Posted 2016-08-07T19:08:29.733

Reputation: 297

5

Open bash, run nano ~/.bashrc and paste this in:

if [[ -t 1 && -x /usr/bin/zsh ]]; then
    exec /usr/bin/zsh
fi

Just change the shell to fish or whatever you want. The -x check is important if you ever re-install Bash -- you won't be able to open it after a fresh install because the exec command will fail and then Bash just closes.

If that happens, delete/rename your .bashrc file here:

C:\Users\<USERNAME>\AppData\Local\lxss\home\<USERNAME>\.bashrc

The -t I believe checks if stdout is open. Not sure why that's important, I copied it from this article.

mpen

Posted 2016-08-07T19:08:29.733

Reputation: 9 109