Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't change default shell #477

Closed
seayxu opened this issue Jun 5, 2016 · 17 comments
Closed

can't change default shell #477

seayxu opened this issue Jun 5, 2016 · 17 comments
Labels

Comments

@seayxu
Copy link

@seayxu seayxu commented Jun 5, 2016

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?

@benhillis

This comment has been minimized.

Copy link
Member

@benhillis benhillis commented Jun 6, 2016

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.

@russalex

This comment has been minimized.

Copy link
Contributor

@russalex russalex commented Jun 6, 2016

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

@seayxu

This comment has been minimized.

Copy link
Author

@seayxu seayxu commented Jun 7, 2016

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

@seayxu seayxu closed this Jun 7, 2016
@fpqc

This comment has been minimized.

Copy link

@fpqc fpqc commented Jun 8, 2016

@seayxu Russalex meant bash.exe -c /bin/zsh

@seayxu

This comment has been minimized.

Copy link
Author

@seayxu seayxu commented Jun 8, 2016

@fpqc I know,but this way is not what i want.
it is not work when opened command windows after closed

@fpqc

This comment has been minimized.

Copy link

@fpqc fpqc commented Jun 8, 2016

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

@seayxu

This comment has been minimized.

Copy link
Author

@seayxu seayxu commented Jun 8, 2016

@fpqc yes,i get it.
Thank you!

@radum

This comment has been minimized.

Copy link

@radum radum commented Sep 3, 2017

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

This might be better ;)

@KornbergFresnel

This comment has been minimized.

Copy link

@KornbergFresnel KornbergFresnel commented Jan 6, 2018

@radum his method is the best and easiest one to solve this issue

@KoldFuzion

This comment has been minimized.

Copy link

@KoldFuzion KoldFuzion commented Feb 14, 2018

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

@therealkenc therealkenc added duplicate and removed duplicate labels Feb 14, 2018
@onwsk8r

This comment has been minimized.

Copy link

@onwsk8r onwsk8r commented Nov 23, 2018

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!

@therealkenc

This comment has been minimized.

Copy link
Collaborator

@therealkenc therealkenc commented Nov 23, 2018

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

...unnecessary.

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

@std4453

This comment has been minimized.

Copy link

@std4453 std4453 commented Jan 23, 2019

@therealkenc
After chsh -s /usr/bin/fish, wsl.exe echo $SHELL still gives /bin/bash, however calling wsl.exe directly enters fish shell with $SHELL being /usr/bin/fish. Why?

@therealkenc

This comment has been minimized.

Copy link
Collaborator

@therealkenc therealkenc commented Jan 23, 2019

however calling wsl.exe directly enters fish shell with $SHELL being /usr/bin/fish. Why?

For you? Couldn't tell ya.

image

@std4453

This comment has been minimized.

Copy link

@std4453 std4453 commented Jan 23, 2019

@therealkenc I'm getting /bin/bash on 2 different devices running 1803 17134.523, after restarting LxssManager and rebooting. Can anybody verify the problem?
image

@therealkenc

This comment has been minimized.

Copy link
Collaborator

@therealkenc therealkenc commented Jan 23, 2019

What does the following return for you:

C:\ wsl.exe /bin/dash -c "grep yourusername /etc/passwd"

Regardless, concrete suggestion would be to get yourself up to 17763. 17134 is almost a year old and I don't have one handy to look. There have been all kinds of changes to the whole WSL interop infrastructure since then, and what was fixed/improved in what release is pretty nebulous. I do know chsh was addressed way earlier but getting onto the current release is a sensible place to start.

@adaaaaaa

This comment has been minimized.

Copy link

@adaaaaaa adaaaaaa commented Mar 10, 2019

@radum
i'm using you method...but how about this?
➜ data git:(master) ✗ chsh -s /bin/zsh
正在更改 captain 的 shell。
密码:
chsh: shell 未更改。
➜ data git:(master) ✗ chsh -s /bin/bash
正在更改 captain 的 shell。
密码:
shell 已更改。
➜ data git:(master) ✗ echo $SHELL
/bin/bash
➜ data git:(master) ✗ chsh -s /bin/zsh
正在更改 captain 的 shell。
密码:
shell 已更改。
➜ data git:(master) ✗ echo $SHELL
/bin/bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.