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)
This might be better đ
@russalex @benhillis Thank you all. I have resolved the problem. My way is add command
bash -c zshto .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 acmd.exesession and typingcmd.exe powershell.exe. Theexecin the second method is unnecessary because itexecs the text that comes after it.exec zshandzshdo the same thing.What I have in my
$HOME/.bashrcisWhat 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 commandcommand -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.
âŚunnecessary.
chsh(1)has worked since the 2017 Fall Creators Update viawsl.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