Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从WSL bash脚本获取windows环境?_Bash_Windows Subsystem For Linux - Fatal编程技术网

如何从WSL bash脚本获取windows环境?

如何从WSL bash脚本获取windows环境?,bash,windows-subsystem-for-linux,Bash,Windows Subsystem For Linux,我正在尝试将Windows用户名导出到Windows101709+Ubuntu(WSL)上的WSL ENV 上面的命令适用于WSL shell,但当我尝试将其添加到~/.profile 我也试着逃避它 export WIN\u USERNAME=$(cmd.exe\/C\\“echo%USERNAME%\” 它也失败了 任何帮助都将不胜感激。 谢谢 这里的问题是在bash脚本中,cmd.exe将尝试访问您的当前路径,这是Windows中不存在的linux路径,因此它应该抛出错误并保留在交互式命令

我正在尝试将Windows用户名导出到Windows101709+Ubuntu(WSL)上的WSL ENV

上面的命令适用于WSL shell,但当我尝试将其添加到
~/.profile

我也试着逃避它
export WIN\u USERNAME=$(cmd.exe\/C\\“echo%USERNAME%\”
它也失败了

任何帮助都将不胜感激。
谢谢

这里的问题是在bash脚本中,cmd.exe将尝试访问您的当前路径,这是Windows中不存在的linux路径,因此它应该抛出错误并保留在交互式命令提示符中。您可以使用powershell访问您的用户名,如下所示:

export WIN_USERNAME="$(powershell.exe -NoProfile -NonInteractive -Command "\$Env:UserName")"

如何将cmd.exe的完整路径指定为/mnt/c/Windows/System32/cmd.exe或类似的内容?
export WIN_USERNAME="$(powershell.exe -NoProfile -NonInteractive -Command "\$Env:UserName")"