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

Add "Run as login shell" option for Bash. #816

Closed
dnt294 opened this issue Aug 8, 2016 · 23 comments
Closed

Add "Run as login shell" option for Bash. #816

dnt294 opened this issue Aug 8, 2016 · 23 comments

Comments

@dnt294
Copy link

dnt294 commented Aug 8, 2016

I've installed and managed to make rvm, ruby and rails work. But after close Bash and open another instance, I can't get ruby or rails worked. I get this error when try to call ruby:

image

Workaround here is to add bash --login every time open a new Bash, while Ubuntu's terminal has an toggle "run as login shell" in its option.

image

@xob
Copy link

xob commented Aug 8, 2016

Another option is to add --login to the shotcut used to launch bash.
image

@benhillis
Copy link
Member

Closing this out because there is a way to run as a login shell (via passing -l or --login to bash.exe)

@aseering
Copy link
Contributor

aseering commented Dec 1, 2016

@benhillis -- The issue as I see it here is that the shortcut to open a shell on Windows does not provide a shell whose environment is comparable to the shortcut to open a shell on Ubuntu. That appears to meet your own criteria for a bug -- it's a point of incompatibility that has resulted in a number of tickets filed by users who don't understand their shell's behavior. It's true that there's a workaround, but the workaround isn't a fix...

I'd really like to see this ticket either re-opened, or closed as a dupe with a reference to some other ticket that's tracking the work.

@benhillis
Copy link
Member

@aseering - agreed, reopening.

@benhillis benhillis reopened this Dec 1, 2016
@aseering
Copy link
Contributor

ping -- any updates on this?

@benhillis
Copy link
Member

@aseering I'll check with the team on their thoughts about adding --login to the default shortcut.

@aseering
Copy link
Contributor

aseering commented Feb 1, 2017

Thanks @benhillis ! For what it's worth, I understand the argument that this is kind of a hack as compared to re-thinking init, or even /bin/login. My question is, as WSL picks up users, will it be easier to transition people from a default minimal shell to a default proper login shell, or from a default --login shell to a proper login shell?

@aseering
Copy link
Contributor

aseering commented Feb 9, 2017

ping -- someone else hit this :-)

@benhillis
Copy link
Member

Unfortunately I couldn't get quorum to add this for Creators Update. User's that want a login shell will have to manually modify their shortcut or use bash.exe -l

@aseering
Copy link
Contributor

aseering commented Feb 9, 2017

Thanks @benhillis for the update. This underlying issue has been around since before freeze for the Anniversary Update (though this particular ticket was filed right after it shipped). Given that this is the sort of change that only becomes harder to make over time, and given that it has missed two releases already, can we take this to mean that you don't plan to implement this change?

@benhillis
Copy link
Member

I would say that since there is such a simple workaround the team feels this is a documentation issue rather than a code defect. I've reached out to @jackchammons to make sure we have a blurb about running bash as a login shell.

@aseering
Copy link
Contributor

aseering commented Feb 9, 2017

Ok -- I mean, there are lots of things with simple workarounds that y'all have chosen to fix. You appear to be confirming that:

  • this one is not likely to be fixed, and
  • the objective is not to match Ubuntus' behavior here.

Please let me know if that's inaccurate.

@benhillis
Copy link
Member

benhillis commented Feb 9, 2017

We have not yet made that determination. I think the greater problem is that to truly match Ubuntu's behavior we should switch over to using /bin/login. That would solve this as well as a number of other issues but it does come with some interesting baggage which is why we have not yet done it.

@aseering
Copy link
Contributor

aseering commented Feb 9, 2017

Your point about /bin/login is a good one. However, what WSL should really do if the objective is to maximize compatibility is to have Ubuntu's /bin/init (or an appropriate one of its many children) fork a login shell. That would solve a whole lot of problems, including this one and including many that /bin/login would not solve. It would also drag quite a large pile of baggage along with it :-)

/bin/login is not a complete solution, but it would be a substantial improvement. /bin/bash --login is also not a complete solution; it would also be an improvement, and a step towards /bin/login. Either way, I hope y'all choose to do something incremental -- it would be wonderful to have all the various system-environment-related details working properly, but I for one will get grumpy if I have to wait until then just to have stock WSL run my dotfiles :-)

Anyway -- thanks for bringing this up with the WSL team, and for the feedback about y'all's thought process. I appreciate knowing what's going on. Also, thanks for all the fixes that you have gotten in :-)

@shawnz
Copy link

shawnz commented Feb 14, 2017

I don't think it is sufficient to add -l to the default shortcut, because I think most users still expect their .profile to be applied even if they run 'bash' from the command line rather than clicking on the shortcut. There is also the issue of 'bash -c xyz' not applying the .profile (see #1404), which is the correct behaviour on Linux, but this makes sense on Linux because the .profile would have already been applied before the user ever has a chance to run 'bash -c'. The /bin/login solution fixes both these issues.

Maybe an alternative solution would be to allow the passing of specific environment variables from Windows into WSL (see #219), thus eliminating the need for .profile? If this were possible, commands which we would normally put in .profile could be run at Windows logon instead. However, this would require additional configuration to fix issues such as the OP's, and it would not be ideal for people who use the same dotfiles on all machines.

@rlabrecque
Copy link

rlabrecque commented Apr 18, 2017

--login is the fist step for sure but making it with /bin/login would definitely be nice.

I wouldn't like to see WSL not conforming to .profile. But it would be neat to see the windows environment variables injected in as a completely separate [optional-but-defaults-to-enabled] feature. (Probably with Win>Linux path fixup i.e. C:\ -> /mnt/c/). Just like the Path is. Hell then I could even make my own path with PATH="$PATH:$Path" if I wanted. Maybe they could be injected with a prefix like $WIN_Path?

@benhillis
Copy link
Member

As of build 16188 when running bash.exe without arguments (or with the ~ argument) bash will be launched as a login shell. The same is true for the new wsl.exe binary (with the exception that wsl launches your user's default shell as a login shell).

@rlabrecque
Copy link

Awesome! Thanks @benhillis. Looking forward to trying it out!

@shawnz
Copy link

shawnz commented May 13, 2017

Thank you so much for this change @benhillis! It really helps.

That said, the approach of only launching bash as a login shell if there are no parameters given causes several scenarios to remain unfixed (particularly #1404 which is concerningly now marked "bydesign"). Why not just always run bash as a login shell if it's launched from bash.exe? Are there still future changes planned with regard to this behaviour?

@mungojam
Copy link

Seems to me that this is fixed in Fall Creator's Update as expected

@thesmart
Copy link

thesmart commented Dec 7, 2017

On a new install of Windows w/ all updates applied, opening Ubuntu still does not source /etc/environment:

$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/var/rbenv/bin"
$ echo $PATH | grep rbenv
$

It appears that creating an executable bash script in /etc/profile.d/* will get loaded upon process restart. This doesn't seem to work with sudo.

@therealkenc
Copy link
Collaborator

This was marked fixedinsiderbuilds as of 16188 (message) implying 16299 FCU. New landing zone for /etc/environment behaviour is #1405.

@trallnag
Copy link

@thesmart, I think this is due to /bin/login not being used by WSL for logging in. /etc/environment is parsed by Linux-PAM and the default config depends on /bin/login.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants