[英]How to set [Bash on Ubuntu on Windows] [environment variables] from [windows path]?
Try to use samza.apache.org/startup/hello-samza/0.7.0/ with Bash On Windows尝试在 Windows 上使用samza.apache.org/startup/hello-samza/0.7.0/与 Bash
it will run它会运行
bin/grid bootstrap
where the flowing code流动的代码在哪里
if [ -z "$JAVA_HOME" ]; then
if [ -x /usr/libexec/java_home ]; then
export JAVA_HOME="$(/usr/libexec/java_home)"
else
echo "JAVA_HOME not set. Exiting."
exit 1
fi
fi
give an error报错
JAVA_HOME not set. Exiting.
on CMD when i run在我运行时在 CMD
echo %JAVA_HOME%
i got我有
C:\Program Files (x86)\Java\jdk1.8.0_102\
I want to import the path data to bash我想将路径数据导入bash
I would try export JAVA_HOME="/mnt/c/Program Files (x86)/Java/jdk1.8.0_102"
to set the JAVA_HOME variable in the bash shell.我会尝试
export JAVA_HOME="/mnt/c/Program Files (x86)/Java/jdk1.8.0_102"
在 bash shell 中设置 JAVA_HOME 变量。
Update (response to your edit):更新(对您的编辑的回应):
I wouldn't recommend trying to automatically import your Windows paths to Bash on Ubuntu on Windows, because the paths have to be converted to be understood by the bash shell ( \\
to /
, C:\\
to mnt/c/
and so on), and because not all of the tools you're probably going to reference will work on both Windows and Linux.我不建议在 Windows 上的 Ubuntu 上尝试自动将 Windows 路径导入 Bash,因为必须转换路径才能被 bash shell 理解(
\\
到/
, C:\\
到mnt/c/
等等) ,并且因为并非您可能要参考的所有工具都适用于 Windows 和 Linux。 Instead, install what you need on the Bash shell using apt-get
(you don't need to use sudo
because BUW loads in a root shell).相反,使用
apt-get
在 Bash shell 上安装你需要的东西(你不需要使用sudo
因为 BUW 在 root shell 中加载)。 Java is probably fine to reference as above, but most things you'll want installed separately on Ubuntu.如上所述,Java 可能很适合参考,但是您需要在 Ubuntu 上单独安装大多数东西。
As a quick solution, I created a powershell script that would作为一个快速的解决方案,我创建了一个 powershell 脚本,它可以
/
/
C:
to /mnt/c
C:
更改为/mnt/c
Output export
commands one line per environment variable每个环境变量一行输出
export
命令
Get-ChildItem Env: | % {"export $($_.Name)=`"$($_.Value.Replace('\\', '/').Replace('C:', '/mnt/c'))`""}
Now, all you need to do is run this script in Powershell, copy the output and paste it in WSL/Ubuntu on Windows to populate the environment variables.现在,您需要做的就是在 Powershell 中运行此脚本,复制输出并将其粘贴到 Windows 上的 WSL/Ubuntu 中以填充环境变量。 You could also put all these commands in a
.sh
file and execute it using bash.您还可以将所有这些命令放在一个
.sh
文件中并使用 bash 执行它。
It is a crude solution, but this worked for me.这是一个粗略的解决方案,但这对我有用。 I'm open to suggestions on improving this.
我愿意接受关于改进这一点的建议。
My path environment variable seems to already have my windows paths there.我的路径环境变量似乎已经有我的 Windows 路径。 But you can run windows programs from Ubuntu on Windows.
但是您可以在 Windows 上从 Ubuntu 运行 Windows 程序。 So you can get environment variables or whatever you like.
所以你可以得到环境变量或任何你喜欢的东西。
export PATH=$PATH:`/mnt/c/Windows/System32/cmd.exe -/C "echo %PATH%"`
It isn't recommended to use Cygwin (licensing, registry corruption, etc).不建议使用 Cygwin(许可、注册表损坏等)。 But below should work.
但下面应该工作。 run is documented to run windows programs from the bash shell it gives you.
run 被记录为从它给你的 bash shell 运行 Windows 程序。
export PATH=$PATH:`run /mnt/c/Windows/System32/cmd.exe -/C "echo %PATH%"`
This one is working for me, by setting WSLENV in the System variables environment.通过在系统变量环境中设置WSLENV ,这个对我有用。
System variables系统变量
export [variable-name]='any-path' for current shell session export [variable-name]='any-path' for current shell session
eg例如
export VSCode='C:/Program Files/....'
echo $VSCODE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.