像"uname -s"这样的命令;从poweshell执行时在WSL中无法识别 [英] Commands like "uname -s" is not recognized in WSL when executed from poweshell

查看:95
本文介绍了像"uname -s"这样的命令;从poweshell执行时在WSL中无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在WSL中执行以下命令:

I need to execute the following command in WSL:

sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

为了从Powershell中执行它,我尝试运行:

In order to execute it from powershell, i tried to run:

Ubuntu1804 run "sudo curl -L 'https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)' -o /usr/local/bin/docker-compose"

但是会发生错误,因为它找不到 uname -s uname -m

But errors occur as it cannot find the value of uname -s and uname -m

uname : The term 'uname' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:107
+ ... ocker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(u ...
+                                                             ~~~~~
    + CategoryInfo          : ObjectNotFound: (uname:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

但是以下命令可以正常工作,因为我在该命令中手动输入了 uname -s uname -m 的值.

But the following command works as i manually entered the value of uname -s and uname -m in that command.

 Ubuntu1804 run "sudo curl -L 'https://github.com/docker/compose/releases/download/1.23.2/docker-compose-Linux-x86_64' -o /usr/local/bin/docker-compose"

有人可以帮助我找到使用Powershell时的方法吗,如何将某些命令的结果合并到另一个命令中并在WSL中执行它?

Can anyone please help me to find when using powershell, how to incorporate the results of some commands to another command and execute it in WSL?

此外,我如何将诸如 $ USER 之类的环境变量的值合并到WSL命令中并从powershell执行?

Also, how can i incorporate the value of environment variables like $USER in WSL commands and execute from powershell?

推荐答案

问题是命令参数中的子表达式 $().PowerShell在表达式模式下解释它们(由于允许扩展的双引号),并在将参数传递给 Ubuntu1804 之前正在寻找名为 uname 的可执行文件.

The problem is your subexpressions $( ) in the argument to the command. PowerShell interprets these in expression mode (because of the double-quotes which allow expansion) and is looking for an executable named uname before passing the argument to Ubuntu1804.

解决方案:

  • run 之后使用stop-parser运算符:-%

  • Use the stop-parser operator after run: --%

翻转引号,以免扩展: ...'sudo curl -L"...

Flip your quotes so expansion doesn't happen: ... 'sudo curl -L " ...

转义子表达式:`$`(`)

要回答如何在WSL命令中包括环境变量:

To answer how you include environment variables in the WSL command:

& Ubuntu1804.exe ... $Env:USER ...

这篇关于像"uname -s"这样的命令;从poweshell执行时在WSL中无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆