Lime logo洛明Lime
← 返回卡片墙幼苗技巧

WSL 访问 Windows 环境变量

Terminal window
# Source - https://superuser.com/a/1340707
# Posted by dualed, modified by community. See post 'Timeline' for change history
# Retrieved 2026-07-29, License - CC BY-SA 4.0
#!/bin/bash
# 'winenv'
cmd.exe /C "echo %$*%" 2>/dev/null | tr -d '\r'
Terminal window
# Source - https://superuser.com/a/1340707
# Posted by dualed, modified by community. See post 'Timeline' for change history
# Retrieved 2026-07-29, License - CC BY-SA 4.0
# Usage
WINHOME=$(wslpath "$(winenv USERPROFILE)")

Terminal window
[limx@archwsl ~]$ pwsh.exe -nop -c '$env:USERPROFILE'
C:\Users\Lime
[limx@archwsl ~]$ powershell.exe '$env:USERPROFILE'
C:\Users\Lime