startingDirectory works with Ubuntu 18.04, but not Ubuntu 20.04 #8309

Closed
opened 2026-01-31 01:26:10 +00:00 by claunia · 17 comments
Owner

Originally created by @henriksen on GitHub (May 20, 2020).

Environment

Windows build number: Microsoft Windows NT 10.0.19041.0
Windows Terminal version (if applicable): 1.0.1401.0 and 1.0.1402.0 (Preview)

Any other software?
Ubuntu 18.04 and Ubuntu 20.04, both running on WSL 2

Steps to reproduce

Install Ubuntu 18.04 and 20.04 on WSL 2.

Install Windows Terminal

I have the following entries in my Terminal settings:

      {
        "guid": "{7f586916-8357-53d4-bb2b-ca96f639898a}",
        "hidden": false,
        "name": "Ubuntu",
        "source": "Windows.Terminal.Wsl",
        "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\glenn"
      },
      {
        "guid": "{392ab1ad-dce3-4251-8b7a-d2d4b25ecb1b}",
        "hidden": false,
        "name": "Ubuntu-20.04",
        "source": "Windows.Terminal.Wsl",
        "startingDirectory": "\\\\wsl$\\Ubuntu-20.04\\home\\glenn"
      },

Expected behavior

When starting one of those profiles, I'd expect my home directory (~/) to be my starting directory.

Actual behavior

When I start Ubuntu, my home folder is ~/ (/home/glenn). When I start Ubuntu-20.04, my home folder is /mnt/c/Users/glenn (my Windows home folder).

If I remove the startingDirectory entry, the starting folder is /mnt/c/Users/glenn on both distros. Using other folders than /home/glenn gives the same result. Works in Ubuntu, not in 20.04.

If I use Powershell, cd to \\wsl$\ubuntu-20.04\home\glenn and run wsl -d Ubuntu-20.04 from that folder, I start in the correct folder, ~/. The same for Ubuntu so here they behave the same.

If I start the Ubuntus from the Start Menu they behave the same, the both start in ~/.

Only when starting Ubuntu 20.04 from the Windows Terminal profile I get the wrong starting folder.

Originally created by @henriksen on GitHub (May 20, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: Microsoft Windows NT 10.0.19041.0 Windows Terminal version (if applicable): 1.0.1401.0 and 1.0.1402.0 (Preview) Any other software? Ubuntu 18.04 and Ubuntu 20.04, both running on WSL 2 ``` # Steps to reproduce Install Ubuntu 18.04 and 20.04 on WSL 2. Install Windows Terminal I have the following entries in my Terminal settings: ```json { "guid": "{7f586916-8357-53d4-bb2b-ca96f639898a}", "hidden": false, "name": "Ubuntu", "source": "Windows.Terminal.Wsl", "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\glenn" }, { "guid": "{392ab1ad-dce3-4251-8b7a-d2d4b25ecb1b}", "hidden": false, "name": "Ubuntu-20.04", "source": "Windows.Terminal.Wsl", "startingDirectory": "\\\\wsl$\\Ubuntu-20.04\\home\\glenn" }, ``` # Expected behavior <!-- A description of what you're expecting, possibly containing screenshots or reference material. --> When starting one of those profiles, I'd expect my home directory (`~/`) to be my starting directory. # Actual behavior <!-- What's actually happening? --> When I start Ubuntu, my home folder is `~/` (`/home/glenn`). When I start Ubuntu-20.04, my home folder is `/mnt/c/Users/glenn` (my Windows home folder). If I remove the `startingDirectory` entry, the starting folder is `/mnt/c/Users/glenn` on both distros. Using other folders than `/home/glenn` gives the same result. Works in Ubuntu, not in 20.04. If I use Powershell, `cd` to `\\wsl$\ubuntu-20.04\home\glenn` and run `wsl -d Ubuntu-20.04` from that folder, I start in the correct folder, `~/`. The same for Ubuntu so here they behave the same. If I start the Ubuntus from the Start Menu they behave the same, the both start in `~/`. Only when starting Ubuntu 20.04 from the Windows Terminal profile I get the wrong starting folder.
Author
Owner

@paulomanrique commented on GitHub (May 21, 2020):

Mine is working fine. One workaround is to include a "cd" in the end of your ~/.bashrc

@paulomanrique commented on GitHub (May 21, 2020): Mine is working fine. One workaround is to include a "cd" in the end of your ~/.bashrc
Author
Owner

@zadjii-msft commented on GitHub (May 22, 2020):

Huh, this is a real thinker. @benhillis / @craigloewen-msft any ideas why this might be? Maybe something weird with the windows<->//wsl$/ interop?

I honestly have no idea why it would work for one distro and not the other.

@zadjii-msft commented on GitHub (May 22, 2020): Huh, this is a real thinker. @benhillis / @craigloewen-msft any ideas why this might be? Maybe something weird with the windows\<->`//wsl$/` interop? I honestly have no idea why it would work for one distro and not the other.
Author
Owner

@henriksen commented on GitHub (May 24, 2020):

One workaround is to include a "cd" in the end of your ~/.bashrc

Yeah, I did that (just to the /etc/bash.bashrc file). Still weird how it works on some distroes and not on others.

@henriksen commented on GitHub (May 24, 2020): > One workaround is to include a "cd" in the end of your ~/.bashrc Yeah, I did that (just to the `/etc/bash.bashrc` file). Still weird how it works on some distroes and not on others.
Author
Owner

@henriksen commented on GitHub (May 24, 2020):

(edited the OP from WLinux to Ubuntu since I copy/pasted the wrong entry from settings. WLinux behaves like Ubuntu, it respects the startingDirectory setting)

@henriksen commented on GitHub (May 24, 2020): (edited the OP from WLinux to Ubuntu since I copy/pasted the wrong entry from settings. WLinux behaves like Ubuntu, it respects the `startingDirectory` setting)
Author
Owner

@henriksen commented on GitHub (May 24, 2020):

Tried it on another, fresh machine. This time with Ubuntu as 20.04 and Ubuntu-18.04. Both worked as expected and started with my home dir as the current path. As specified. Just a freak thing I guess.

@henriksen commented on GitHub (May 24, 2020): Tried it on another, fresh machine. This time with `Ubuntu` as 20.04 and `Ubuntu-18.04`. Both worked as expected and started with my home dir as the current path. As specified. Just a freak thing I guess.
Author
Owner

@warpdesign commented on GitHub (Jun 5, 2020):

It doesn't seem to work for me either.

Here is my profile for Ubuntu-20.04:

        {
            "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
            "hidden": false,
            "name": "Ubuntu-20.04",
            "cursorShape": "underscore",
            "source": "Windows.Terminal.Wsl",
            "colorScheme": "One Half Dark",
            "padding" : "5, 5, 5, 5",
            "fontSize": 11,
            "closeOnExit" : true,
            "startingDirectory": "/home"
        }

Instead of opening in /home it opens in the default which is ~.

@warpdesign commented on GitHub (Jun 5, 2020): It doesn't seem to work for me either. Here is my profile for Ubuntu-20.04: ``` { "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}", "hidden": false, "name": "Ubuntu-20.04", "cursorShape": "underscore", "source": "Windows.Terminal.Wsl", "colorScheme": "One Half Dark", "padding" : "5, 5, 5, 5", "fontSize": 11, "closeOnExit" : true, "startingDirectory": "/home" } ``` Instead of opening in `/home` it opens in the default which is `~`.
Author
Owner

@DHowett commented on GitHub (Jun 5, 2020):

@warpdesign Since Terminal is a Windows application, it expects paths in Windows format.

To open in /home for Ubuntu-20.04, you'll want //wsl$/Ubuntu-20.04/home.

@DHowett commented on GitHub (Jun 5, 2020): @warpdesign Since Terminal is a Windows application, it expects paths in Windows format. To open in `/home` for `Ubuntu-20.04`, you'll want `//wsl$/Ubuntu-20.04/home`.
Author
Owner

@warpdesign commented on GitHub (Jun 5, 2020):

It does not work with //wsl$/Ubuntu-20.04/home either: it still opens in ~.

Also tried with "\\\\wsl$\\Ubuntu-20.04\\home\\" without luck.

Btw since the source is set to Windows.Terminal.wsl, shouldn't it accept linux paths?

Note: I tried to do the same with the wt.exe command but it still fails to change the startup directory.

wt -p Ubuntu-20.04 -d \\wsl$\Ubuntu-20.04\home

@warpdesign commented on GitHub (Jun 5, 2020): It does not work with `//wsl$/Ubuntu-20.04/home` either: it still opens in `~`. Also tried with `"\\\\wsl$\\Ubuntu-20.04\\home\\"` without luck. Btw since the source is set to `Windows.Terminal.wsl`, shouldn't it accept linux paths? **Note:** I tried to do the same with the `wt.exe` command but it still fails to change the startup directory. > wt -p Ubuntu-20.04 -d \\\\wsl$\Ubuntu-20.04\home
Author
Owner

@warpdesign commented on GitHub (Jun 8, 2020):

@henriksen I think I found the "problem": Ubuntu-20.04 automatically changes the directory to the user's home in .bashrc:

cd ~

So the startingDirectory option actually works but directory is changed back to the user's home when .bashrc is executed.

Removing this line obviously fixes the problem.

@warpdesign commented on GitHub (Jun 8, 2020): @henriksen I think I found the "problem": Ubuntu-20.04 automatically changes the directory to the user's home in `.bashrc`: > cd ~ So the `startingDirectory` option actually works but directory is changed back to the user's home when `.bashrc` is executed. Removing this line obviously fixes the problem.
Author
Owner

@warpdesign commented on GitHub (Jun 8, 2020):

Hmm.. after some more digging there is actually a problem that seems to be related to the status of the WSL distro:

  • if it is running, startingDirectory works as expected
  • if it is not running, startingDirectory becomes %USERPROFILE% (/mnt/c/Users/xxx)

On this video the distro is not running when I first open an Ubuntu tab and the starting directory becomes my Windows user profile (not expected). But when I open a new Ubuntu tab, the distro is running, and the starting directory is the expected (set in the settings file) one: ~/Dev.

wsl-startup

@warpdesign commented on GitHub (Jun 8, 2020): Hmm.. after some more digging there is actually a problem that seems to be related to the status of the WSL distro: - if it is running, startingDirectory works as expected - if it is not running, startingDirectory becomes %USERPROFILE% (`/mnt/c/Users/xxx`) On this video the distro is not running when I first open an Ubuntu tab and the starting directory becomes my Windows user profile (not expected). But when I open a new Ubuntu tab, the distro is running, and the starting directory is the expected (set in the settings file) one: `~/Dev`. ![wsl-startup](https://user-images.githubusercontent.com/199648/84084789-6f1c8880-a9e4-11ea-8669-6353b2be8a8b.gif)
Author
Owner

@DHowett commented on GitHub (Jun 8, 2020):

Can you share .bashrc?

@DHowett commented on GitHub (Jun 8, 2020): Can you share `.bashrc`?
Author
Owner

@ghost commented on GitHub (Jun 13, 2020):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost commented on GitHub (Jun 13, 2020): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Author
Owner

@henriksen commented on GitHub (Jun 14, 2020):

Can you share .bashrc?

Both .bashrcs are here: https://gist.github.com/henriksen/4ebbf1e5b38c23da68f5dfe987d507b8
No cd in any of them as far as I can see.

@henriksen commented on GitHub (Jun 14, 2020): > Can you share `.bashrc`? Both `.bashrc`s are here: https://gist.github.com/henriksen/4ebbf1e5b38c23da68f5dfe987d507b8 No `cd` in any of them as far as I can see.
Author
Owner

@henriksen commented on GitHub (Jun 14, 2020):

Hmm.. after some more digging there is actually a problem that seems to be related to the status of the WSL distro:

Makes no difference in my case.
pVvrPq8nwP

@henriksen commented on GitHub (Jun 14, 2020): > Hmm.. after some more digging there is actually a problem that seems to be related to the status of the WSL distro: Makes no difference in my case. ![pVvrPq8nwP](https://user-images.githubusercontent.com/121837/84603238-2570e980-ae8d-11ea-8ac5-7c5e6fe145e9.gif)
Author
Owner

@pcolmer commented on GitHub (Jun 15, 2020):

I'm seeing the same problem but, in my case, I've pinned it down to the source config entry. If I have two Ubuntu entries:

            {
                "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
                "hidden": false,
                "name": "Ubuntu",
                "source": "Windows.Terminal.Wsl",
                "commandline": "wsl.exe ~"
            },
            {
                "guid": "{daaee0d5-f525-4b10-98d1-d0ed1ede9f72}",
                "hidden": false,
                "name": "Ubuntu-no-source",
                // "source": "Windows.Terminal.Wsl",
                "commandline": "wsl.exe ~"
            },

then the "Ubuntu-no-source" will always go into ~/ whereas "Ubuntu" will always go into "/mnt/c/users/phili":

ZAe2seVUdu

The above shows that it doesn't matter which order I open them in either.

@pcolmer commented on GitHub (Jun 15, 2020): I'm seeing the same problem but, in my case, I've pinned it down to the `source` config entry. If I have two Ubuntu entries: ``` { "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}", "hidden": false, "name": "Ubuntu", "source": "Windows.Terminal.Wsl", "commandline": "wsl.exe ~" }, { "guid": "{daaee0d5-f525-4b10-98d1-d0ed1ede9f72}", "hidden": false, "name": "Ubuntu-no-source", // "source": "Windows.Terminal.Wsl", "commandline": "wsl.exe ~" }, ``` then the "Ubuntu-no-source" will **always** go into `~/` whereas "Ubuntu" will always go into "/mnt/c/users/phili": ![ZAe2seVUdu](https://user-images.githubusercontent.com/1979931/84661173-dd47da80-af11-11ea-8925-c34aa8fb0ba4.gif) The above shows that it doesn't matter which order I open them in either.
Author
Owner

@paulomanrique commented on GitHub (Jul 8, 2020):

@warpdesign you need to add your username directory, not only "home". Mine is:

"startingDirectory": "//wsl$/Ubuntu-20.04/home/paulo"

@paulomanrique commented on GitHub (Jul 8, 2020): @warpdesign you need to add your username directory, not only "home". Mine is: `"startingDirectory": "//wsl$/Ubuntu-20.04/home/paulo"`
Author
Owner

@zadjii-msft commented on GitHub (Aug 5, 2020):

Hey so this thread is pretty old at this point. If I'm reading it all correctly:

  • OP's (@henriksen) original issue about the distros treating the starting directory differently went away on its own.
  • @warpdesign is having a different issue, where subsequent seemingly open in different directories (https://github.com/microsoft/terminal/issues/6022#issuecomment-640911570).
  • @pcolmer is having yet another issue with the commandline and the starting directory

To try and untangle this mess, @warpdesign & @pcolmer, could you move your issues to another thread, so we can track that one independently? I'm betting that there's some weird bashrc/profile/whatever-other-config hijinks going on, but I'd rather not further muddle this thread.

Thanks all (and sorry for the delayed replies)!

@zadjii-msft commented on GitHub (Aug 5, 2020): Hey so this thread is pretty old at this point. If I'm reading it all correctly: * OP's (@henriksen) original issue about the distros treating the starting directory differently went away on its own. * @warpdesign is having a different issue, where subsequent seemingly open in different directories (https://github.com/microsoft/terminal/issues/6022#issuecomment-640911570). * @pcolmer is having yet another issue with the `commandline` and the starting directory To try and untangle this mess, @warpdesign & @pcolmer, could you move your issues to another thread, so we can track that one independently? I'm betting that there's some weird `bashrc`/`profile`/`whatever-other-config` hijinks going on, but I'd rather not further muddle this thread. Thanks all (and sorry for the delayed replies)!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#8309