保持Windows和“Bash on Ubuntu on Windows”之间的路径同步

pepwfjgg  于 2023-03-01  发布在  Windows
关注(0)|答案(2)|浏览(144)

保持Windows 10路径和“Bash on Ubuntu on Windows(WSL)”路径同步的最佳方法是什么?
我已经将Windows 10路径(转换为bash兼容)附加到.bashrc,但bash shell似乎没有拾取它。
我采取的步骤:
1.获取Windows路径〉echo %PATH%
1.选择相关路径并转换为bash兼容(例如,C:\Java变为/mnt/c/Java)
1.启动bash并编辑.bashrc
1.附加到.bashrc,例如〉导出路径=${PATH}:/bin:/mnt/c/Java/bin:/mnt/c/节点

mspsb9vt

mspsb9vt1#

从Insider build 145963(ish)开始,您无需在.bashrc中附加Windows路径:
在后续版本中,以及从Creators Update开始,WSL会自动将Windows路径附加到您的Bash路径,允许您从Bash中启动Windows可执行文件,而无需输入路径上可执行文件的绝对文件夹位置。
例如,导航到C:驱动器,创建一个文本文件并在记事本中打开:

$ cd /mnt/c/temp
$ echo Hello > hello.txt
$ Notepad.exe ./hello.txt

提示:不要忘记.exe扩展名--它告诉Linux请求WSL启动.exe

nr9pn0ug

nr9pn0ug2#

我想那是你希望的。
自动将您的Windows路径转换为Bashrc:
https://github.com/hypolas/wintobashpath
https://github.com/hypolas/wintobashpath/releases/tag/v1.0.0

echo %PATH%
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\PowerShell\7\;C:\Program Files\nodejs;;E:\Program Files\Git\cmd;C:\Program Files\Go\bin;C:\Users\hypolas\AppData\Local\Microsoft\WindowsApps;C:\Users\hypolas\AppData\Local\Programs\Microsoft VS Code\bin;E:\msys64-2023\mingw64\bin;C:\Users\hypolas\AppData\Roaming\npm;C:\Users\hypolas\go\bin

变成:

/mingw64/bin:/usr/bin:/c/Users/hypolas/bin:/c/Users/hypolas/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/usr/bin:/mingw64/bin:/usr/bin:/c/Users/hypolas/bin:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files/dotnet:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/Program Files/PowerShell/7:/c/Program Files/nodejs

我是为了自己。

相关问题