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
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"
},
When starting one of those profiles, I'd expect my home directory (~/) to be my starting directory.
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.
Mine is working fine. One workaround is to include a "cd" in the end of your ~/.bashrc
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.
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.
(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)
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.
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 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.
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.04home
@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.
Hmm.. after some more digging there is actually a problem that seems to be related to the status of the WSL distro:
/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.

Can you share .bashrc?
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.
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.
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.

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":

The above shows that it doesn't matter which order I open them in either.
@warpdesign you need to add your username directory, not only "home". Mine is:
"startingDirectory": "//wsl$/Ubuntu-20.04/home/paulo"
Hey so this thread is pretty old at this point. If I'm reading it all correctly:
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)!
Most helpful comment
I'm seeing the same problem but, in my case, I've pinned it down to the
sourceconfig entry. If I have two Ubuntu entries:then the "Ubuntu-no-source" will always go into
~/whereas "Ubuntu" will always go into "/mnt/c/users/phili":The above shows that it doesn't matter which order I open them in either.