microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.24k stars 811 forks source link

Non-login shell even with `--shell-type login` #11152

Open alexeyr-ci opened 7 months ago

alexeyr-ci commented 7 months ago

Windows Version

Microsoft Windows [Version 10.0.22621.3085]

WSL Version

2.0.9.0

Are you using WSL 1 or WSL 2?

Kernel Version

5.15.133.1-1

Distro Version

Ubuntu 22.04

Other Software

PS C:\Users\Alexey> wsl --version
WSL version: 2.0.9.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59
MSRDC version: 1.2.4677
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.3085

Repro Steps

Run wsl or wsl --shell-type login from Windows.

Expected Behavior

The WSL shell should be a login shell (according to https://github.com/microsoft/WSL/issues/816#issuecomment-301216901). In particular, it should source .profile. This was working until a few days ago (with just wsl).

Actual Behavior

It isn't a login shell: .profile is not sourced and

alexey@DESKTOP-41AVESA:/mnt/c/Users/Alexey$ shopt login_shell
login_shell     off

Diagnostic Logs

No response (I've tried to use Feedback Hub according to https://github.com/Microsoft/WSL/blob/master/CONTRIBUTING.md#9-collect-wsl-logs-with-feedback-hub, but I don't see "Attachments"; instead it only attached a screenshot of the screen by default which wouldn't be helpful).

github-actions[bot] commented 7 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

ghost commented 7 months ago

I don't see what you see when I test. Can you post your ~/.wslconfig & /etc/wsl.conf

Typically, we like logs from here: https://github.com/Microsoft/WSL/blob/master/CONTRIBUTING.md#8-collect-wsl-logs-recommended-method

alexeyr-ci commented 7 months ago

Sorry, I was going to include them but forgot.

~/.wslconfig

[wsl2]
memory=16GB
processors=4

[experimental]
autoMemoryReclaim=gradual
sparseVhd=true

/etc/wsl.conf:

[boot]
systemd=true

[user]
default=alexey

Logs: WslLogs-2024-02-14_01-15-52.zip.

JojOatXGME commented 6 months ago

For me, it works when I open a "normal" interactive shell,

> wsl.exe -d Ubuntu
$ shopt login_shell
login_shell     on
$ whereis vlc
vlc: /snap/bin/vlc

but not when passing commands directly as an argument.

> wsl.exe -d Ubuntu -- shopt login_shell
login_shell     off
> wsl.exe -d Ubuntu -- whereis vlc
vlc:
> wsl.exe -d Ubuntu -- vlc
/bin/bash: line 1: vlc: command not found

I installed VLC as a snap to reproduce the issue. Snaps are installed within /snap/bin/

$ sudo snap install vlc
vlc 3.0.19 from VideoLAN✓ installed
alexeyr-ci commented 6 months ago

but not when passing commands directly as an argument.

That's the expected behavior according to https://github.com/microsoft/WSL/issues/816#issuecomment-301216901 (unless it was changed later, the comment is from 2017):

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).

JojOatXGME commented 6 months ago

@alexeyr-ci Thanks for the info. I guess it makes sense, as it seems to match the behavior of sshd.

$ ssh 172.31.192.139 shopt login_shell
login_shell     off

Unfortunately, in my case with NixOS, the distro is not using the standard paths, so I end up with almost nothing in the PATH, not even bash or ls. 😆 (I am not sure how they fixed the initial environment when connecting over ssh.) I cannot help you with your issue then.

OneBlue commented 4 months ago

I indeed cannot reproduce the issue:

wsl --shell-type login
$ shopt login_shell
login_shell     on

@alexeyr-ci: Can you share details about your distro and default shell ?

alexeyr-ci commented 4 months ago

The distro is Ubuntu, and the shell is bash. Nothing special here.