I need to get the path to the Windows user's home directory /mnt/c/Users/username from within WSL, is it stored somewhere?
If not, is username stored somewhere? I'll just assume the /mnt/c/Users part doesn't change.
Thanks!
vGet it using cmd.exe and parse it to WSL path using wslpath (requires an updated WSL with wslpath installed):
Bash
WIN_HOME_RAW="$(cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)"
WIN_HOME="$(wslpath $WIN_HOME_RAW)"
Fish
set WIN_HOME_RAW (cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)
set -gx WIN_HOME (wslpath $WIN_HOME_RAW)
You may simply use wslpath and wslvar together as below:
$ wslpath "$(wslvar USERPROFILE)"
which will return something like this:
/mnt/c/Users/{USERNAME}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With