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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI 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?
The default distribution on WSL is Ubuntu, and for Ubuntu:
bash
dash
So by transitive property, assuming that you meant "default interactive", I guess we can say that the default shell for WSL is bash
.
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:
root
)./bin/sh
is linked to for running system and other "POSIX" scripts in as fast and compatible a manner as possible.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.
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.
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.
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 :-).
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
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.
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.
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
.
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.