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

SHELL environment variable is set incorrectly #136

Closed
tomjaguarpaw opened this issue Dec 10, 2018 · 21 comments
Closed

SHELL environment variable is set incorrectly #136

tomjaguarpaw opened this issue Dec 10, 2018 · 21 comments

Comments

@tomjaguarpaw
Copy link

In my WSL I have my shell set (using chsh) to zsh. When I launch wsltty I do indeed get a zsh shell, but the SHELL environment variable is set to /bin/bash. This did not happen under the default Windows terminal. Using the default Windows terminal the SHELL environment variable was set correctly to /bin/zsh. Do you have any idea why this is happening? I wondered if #95 was related but I was not sure.

@mintty
Copy link
Owner

mintty commented Dec 10, 2018

None of mintty, wslbridge, or the profile scripts on the system where I reproduced this (kali-linux) set the SHELL variable. Somebody with detailed knowledge of what happens under the hood when logging in to Linux may be needed to give us a clue. @rprichard perhaps?

@kailiu42
Copy link

I'm running openSUSE Tumbleweed WSL and I did notice this issue too.

@nhoad
Copy link

nhoad commented Feb 2, 2019

I'm on ArchWSL, same issue here.

@j-c-m
Copy link

j-c-m commented Feb 6, 2019

rprichard/wslbridge#37

@mintty
Copy link
Owner

mintty commented Feb 9, 2019

That patch is based on a rather old commit of wslbridge and I do not see right away how to apply it to the current version. It would be good to consolidate this first, then convince rprichard to accept the patch, and then it can be integrated with wsltty. Provided it works, of course.

@j-c-m
Copy link

j-c-m commented Feb 9, 2019

Is that the wrong repo for wslbridge? I don't see any commits that would conflict with the patch -- or really any significant ongoing work at all.

The patch works, when setting up a login session and changing the shell it is correct to set the SHELL variable. For reference see linux login.c:

https://github.com/karelzak/util-linux/blob/d55db6724ce938ec7d5e6d4d3ed11379ade33266/login-utils/login.c#L1024

@mintty
Copy link
Owner

mintty commented Feb 10, 2019

The repo is the right one.
Why don't you follow the suggestion in my previous comment?
You've based your patch on an outdated commit of wslbridge, if you rebase it to the current version, it will be easy to apply and test it. That might get it accepted in wslbridge or if it isn't, it could be applied when building wsltty. It's your turn.

@j-c-m
Copy link

j-c-m commented Feb 10, 2019

The patch would cleanly apply to the master branch of wslbridge despite being 1 unrelated commit behind.

Regardless, I have rebased so it is now 0 commits behind, and also built a wslbrigdge-backend binary including the patch for any testing, anyone wishes to do.

https://github.com/j-c-m/wslbridge/releases/tag/0.2.5-dev-shellEnv

@mintty
Copy link
Owner

mintty commented Feb 10, 2019

Well, your referred comment says

An update for 34ec0e4 / #17 to also set the SHELL environment variable.

which commit is dated 16 Nov 2017, maybe the backend hasn't changed so much since then... I'll check out again.

@j-c-m
Copy link

j-c-m commented Feb 10, 2019

I understand the confusion now, that commit was referenced for the concept. The actual update I made was against the newest master at the time.

@thetrompf
Copy link

thetrompf commented Feb 20, 2019

I just created a shortcut with the following command line:

%LOCALAPPDATA%\wsltty\bin\mintty.exe --configdir="%APPDATA%\wsltty" -~ -e %LOCALAPPDATA%\wsltty\bin\wslbridge.exe -t -l -eSHELL=/bin/zsh -eSHLVL=0 -C~

image

image

@mintty
Copy link
Owner

mintty commented Feb 21, 2019

Thanks for the note. This is not a generic solution, however, and it could be accomplished as well within the WSL startup scripts. Maybe even better there as you would be able to determine the actual shell being used and set that into SHELL.

@thetrompf
Copy link

I am well aware, it was meant as a workaround, until a generic solution is found.

@sskeirik
Copy link

sskeirik commented Apr 8, 2019

I recently ran into this issue as well. As an alternative solution to the complex mintty invocation shown above, I seem to be able to just add a:

[ -z "$ZSH_VERSION" ] || export SHELL="/bin/zsh"

snippet into my .zshrc to correct this issue. As far as I can tell, at least on my current WSL setup, there is no need for SHELL to be set correctly in the /etc system-wide scripts that are usually run first.

EDIT: Obviously, this only works for zsh and will need to be customized for any other shell, e.g. apparently fish exports a version variable.

@ckuai
Copy link

ckuai commented Sep 19, 2019

I recently ran into this issue as well. As an alternative solution to the complex mintty invocation shown above, I seem to be able to just add a:

[ -z "$ZSH_VERSION" ] || export SHELL="/bin/zsh"

Midnight commander also due to this issue can't use shell.... it turns out also due to the shell variable is not set to shell as in /etc/passwd but default to /bin/bash. Both default WSL1 terminal and the new Windows terminal preview do not have this issue.

setting [ -z "$ZSH_VERSION" ] || export SHELL="/bin/zsh" in .zshrc helps.

@mintty
Copy link
Owner

mintty commented Sep 19, 2019

@Biswa96, would wslbridge2/hvpty handle this better?

@j-c-m
Copy link

j-c-m commented Sep 19, 2019

rprichard/wslbridge#37

@Biswa96
Copy link
Contributor

Biswa96 commented Sep 19, 2019

For my wslbridge2 repo, as I told before, $SHELL is handled by /init and those backends fork from them. So, backends don't interfere with it. Can you provide any case where $SHELL is shown incorrectly?

@j-c-m
Copy link

j-c-m commented Sep 20, 2019

Are there plans to switch to @Biswa96 wslbridge2? It seems to fix this issue (and others) and the original wslbridge appears abandoned.

@mintty
Copy link
Owner

mintty commented Sep 22, 2019

Yes, mintty 3.0.3 is in preparation and wsltty release shall follow it.

@mintty
Copy link
Owner

mintty commented Oct 2, 2019

Released 3.0.5 with new gateway.

@mintty mintty closed this as completed Oct 2, 2019
antoineco added a commit to antoineco/dotfiles that referenced this issue Oct 6, 2019
* Increase CharNarrowing to mitigate a rendering issue with heavy glyphs
  mintty/mintty#922

* Uses wslbridge2, which sets the SHELL environment variable correctly
  mintty/wsltty#136
antoineco added a commit to antoineco/dotfiles that referenced this issue Oct 6, 2019
* Disables automatic character narrowing for technical symbols
  mintty/mintty#922

* Uses wslbridge2, which sets the SHELL environment variable correctly
  mintty/wsltty#136
antoineco added a commit to antoineco/dotfiles that referenced this issue Jan 17, 2020
* Disables automatic character narrowing for technical symbols
  mintty/mintty#922

* Uses wslbridge2, which sets the SHELL environment variable correctly
  mintty/wsltty#136
antoineco added a commit to antoineco/dotfiles that referenced this issue Mar 24, 2020
* Disables automatic character narrowing for technical symbols
  mintty/mintty#922

* Uses wslbridge2, which sets the SHELL environment variable correctly
  mintty/wsltty#136
antoineco added a commit to antoineco/dotfiles that referenced this issue Aug 26, 2021
* Disables automatic character narrowing for technical symbols
  mintty/mintty#922

* Uses wslbridge2, which sets the SHELL environment variable correctly
  mintty/wsltty#136
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants