WSL: can't change default shell

I have installed the Zsh,and run command sudo chsh -s zsh,but zsh not work.

root@XY:~# echo $SHELL
/bin/bash

windows 10 preview 14352

what should i do?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 6
  • Comments: 17 (2 by maintainers)

Most upvoted comments

# Launch Zsh
if [ -t 1 ]; then
exec zsh
fi

This might be better 😉

@russalex @benhillis Thank you all. I have resolved the problem. My way is add command bash -c zsh to .bashrc file.

Another option I have seen people do is use the command bash -c zsh.

So these workarounds you guys have look like they were written by Windows guys 😛 The first method - bash -c zsh - opens a new bash shell which then executes ZSH. In other words, it runs bash, runs bash, and then runs ZSH. It would be akin to opening a cmd.exe session and typing cmd.exe powershell.exe. The exec in the second method is unnecessary because it execs the text that comes after it. exec zsh and zsh do the same thing.

What I have in my $HOME/.bashrc is

 [[ $- == *i* ]] && $(command -v zsh) || echo "ZSH is not installed"

What this does:

  • [[ $- == *i* ]] && says “if this is an interactive session (ie not started by a script), do what comes next”. If not, continue as if nothing happened. This is a safeguard because while Bash scripts are 99% compatible with ZSH, some integral parts such as arrays and strings have some significant differences that might make your script take a dump.
  • $(command -v zsh) runs the command command -v zsh, which will print the full path to ZSH (eg /bin/zsh) if there is a binary with that name on the path. The $() executes the output of whatever is between the parens- in this case the full path to ZSH or nothing if it cannot be found. The $() will return the exit status of that command if it is nonzero.
  • || echo "ZSH is not installed" says “if that last command returned a nonzero exit status” (||), “execute whatever follows”. In this case, what follows is a friendly message telling you ZSH is not installed.

HTH!

Then you should just put /bin/zsh in .bashrc. No need to do bash -c in that case.

For a workaround you can launch zsh from your .bashrc file. We don’t run login which is the component that normally sets those things up.

What I have in my $HOME/.bashrc is…

…unnecessary.

chsh(1) has worked since the 2017 Fall Creators Update via wsl.exe. HTH.

Along with everything above, to get my terminal to open to zsh, I had to go to

Terminal > Preferences > General

Then change the “Shells open with:” option to: Default login shell screen shot 2018-02-14 at 1 48 56 pm