保持Windows和'在Windows上的Bash on Ubuntu'之间的路径同步

Vik*_*Vik 3 windows bash shell ubuntu windows-subsystem-for-linux

什么是保持Windows 10 Path和'Bash on Ubuntu on Windows(WSL)'路径同步的最佳方法?

我已将Windows 10 Path(将其转换为bash兼容)附加到.bashrc,但bash shell似乎没有将其拾取.

我采取的步骤:

  1. 获取Windows路径> echo%PATH%
  2. 选择相关路径并转换为兼容bash(例如C:\ Java变为/ mnt/c/Java)
  3. 启动bash并编辑.bashrc
  4. 附加到.bashrc例如> export PATH = $ {PATH}:/ bin:/ mnt/c/Java/bin:/ mnt/c/node

Ric*_*ner 5

从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
Run Code Online (Sandbox Code Playgroud)

提示:不要忘记.exe扩展 - 这就是告诉Linux要求WSL启动.exe的原因