1

I don't use Windows and I don't have a copy available. I'm wanting to know what is the default shell for WSL2? Does it ship with sh, Bash, or ZSH? Or, does it use PowerShell -- which I know runs on WSL2 too.

Is this documented anywhere?

9
  • I can only speak for the ubuntu version but the default shell is bash regardless of how you start it. It comes with dash, rbash, and bash installed but no zsh or powershell.
    – jesse_b
    Aug 19, 2020 at 17:19
  • 2
    While not off topic, I suspect the people who can answer this definitively will be on Super User, not here. I'm 90% sure it's bash, but I'd ask on SU in your place. Not a lot of windows users here.
    – terdon
    Aug 19, 2020 at 17:20
  • 1
    @EvanCarroll: I use wsl ubuntu on my personal machine and I can tell you for sure it's not powershell.
    – jesse_b
    Aug 19, 2020 at 17:29
  • 1
    WSL supports an increasing number (Ubuntiu, SUSE, Kaki, etc.) of Linux distributions. The default shell and other available shells depend on the particular distribution you invoke.
    – fpmurphy
    Aug 20, 2020 at 2:32
  • 1
    FWIW, I thought the question was absolutely appropriate for Unix & Linux and was surprised at finding a sole downvote on it. IMHO, it would require someone with both WSL and Linux knowledge to answer, but more so Linux. And unfortunately you are also correct that there is (still) a lot of toxic behavior on Super User that doesn't seem to exist nearly as much here. Oct 6, 2021 at 22:57

4 Answers 4

3

Short answer

The default distribution on WSL is Ubuntu, and for Ubuntu:

  • The default interactive shell is bash
  • The default non-interactive shell is dash

So by transitive property, assuming that you meant "default interactive", I guess we can say that the default shell for WSL is bash.

More detail

I thought about answering this a few days ago, but it didn't really seem to warrant the "bump". However, since Community bot picked this question today to auto-bump (since there's no accepted answer), I'll give it a slightly different spin.

First, as I think you are aware now, WSL supports many different Linux distributions. You can install a number of them from the Microsoft Store in Windows, or you can import a rootfs for most other distributions.

And I really prefer (and agree with) Debian's definitions of "default" when it comes to shells. There is always:

  • a default interactive shell, that is assigned by default to users when created (and to root).
  • a default non-interactive shell that is, by definition, whatever /bin/sh is linked to for running system and other "POSIX" scripts in as fast and compatible a manner as possible.

Some history

  • Early WSL Days

    When WSL was first announced, it was (perhaps poorly) called "Bash on Ubuntu on Windows". At that point, I think it would have been fairly obvious to answer your question with "Bash".

    It was common to start your WSL/Ubuntu session using a bash.exe command to launch WSL. This would always launch to the bash shell inside an Ubuntu instance, even if the user's shell had been redefined in /etc/passwd.

    The ubuntu.exe command (or one of its variants), on the other hand, would launch the WSL Ubuntu distribution into the user's /etc/passwd shell.

  • Recent history

    Then we came to a gray area, where I don't believe it would be possible to say that there was any "default distribution" for WSL. You first installed/enabled WSL, then you picked a distribution from the Microsoft Store.

    The bash.exe method of starting was "semi-deprecated" (it was called a "historical command" in the Microsoft doc), and the new wsl.exe replaced it. It always defaulted to the user's /etc/passwd-defined shell, but any executable could be started as the parent process via wsl --execute <appname> (or wsl -e).

    During this time, it would have been difficult to answer your question with anything other than "it depends on the distro", since there wasn't a "default" distro.

  • Today

    As of Windows 10 release 21H2 and Windows 11, there is a new WSL installation process. The base wsl command is shipped with Windows, but it needs to be enabled via wsl --install. This command, once again, does default to Ubuntu as the default distribution.

    So as of now, it's (once again) fair to say that Ubuntu is the default distribution for WSL.

  • Tomorrow

    Who knows? It obviously has changed quite a bit over the 5 year history of WSL so far, so I'm sure it could change again :-).

0

If you start wsl using bash.exe then it's bash apparently! But newer releases of Windows 10 have changed things a bit.

Have a look at this: change default shell for wsl

0

I can't find any concrete documentation but on the microsoft wsl reference page it says:

wsl.exe

Below is a list containing all options when using wsl.exe as of Windows Version 1903.

Using: wsl [Argument] [Options...] [CommandLine]

Arguments for running Linux commands

  • Without arguments

If no command line is provided, wsl.exe launches the default shell.


I couldn't find anything on that page that actually defines the default shell, however on the frequently asked questions page it says:

What is Bash?

Bash is a popular text-based shell and command-language. It is the default shell included within Ubuntu and other Linux distros, and in macOS. Users type commands into a shell to execute scripts and/or run commands and tools to accomplish many tasks.

0

The default shell on WSL differs by distribution. The distribution sets policy on what constitutes its default shell and what shells it ships.

When you create an account on first setting up, you are provided with the distro's default interactive shell. Note that this differs from the default shell in some cases. For example, Debian and Ubuntu's default shell is /bin/sh, which is usually dash, but because dash is not a good interactive shell, bash is the default for new users if one is not specified.

You can use chsh to change your user's shell, and if you do that, WSL will load that shell, at least for interactive uses. I have mine set to /bin/zsh.

You are unlikely to find PowerShell as a viable option on most Linux distributions, since it differs markedly from POSIX and most software on Linux assumes that there's a POSIX shell. Many pieces of software also assume that the user's shell is POSIX compliant or if not, at least one of csh or fish, and using PowerShell there is likely to cause unintended breakage.

3
  • Your last paragraph is compete rubbish. Linux distributions do not assume a user's shell is POSIX-compliant. Bash in its default mode is not POSIX-compliant. Dash which is the default shell of a number of distribution does not even attempt to be POSIX-compliant.
    – fpmurphy
    Aug 20, 2020 at 4:23
  • bash and dash are definitely intended to be POSIX compliant implementations of sh. They may add additional features, but they are supposed to implement sh properly. And there are many programs, such as Vim and OpenSSH, that do indeed use $SHELL or the user's shell to specify commands to run instead of /bin/sh.
    – bk2204
    Aug 20, 2020 at 23:36
  • Any shell can claim to be "POSIX-compliant". The devil is in the detail. For example, dash is not fully POSIX-compliant as it does not support Internationalization (I18N) and localization (L12N) nor multi-byte character encoding. Another example,bash requires specific configuration/invocation to even be "POSIX-compliant", i.e POSIXLY_CORRECT, --posix, etc.
    – fpmurphy
    Aug 21, 2020 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.