【发布时间】:2020-02-11 09:57:10
【问题描述】:
我正在尝试通过 Power-Shell CLI 在Windows 10 中执行以下简单命令。我该怎么做?
ID=test001 ./initializeID.sh
initializeID.sh 在哪里:
#!/bin/bash
echo "Initializing for ID: $ID"
DPPROG="{\"title\":\"Test \", \"Id\": \"$ID\"}"
curl -H "Content-type: application/json" -d "$DPPROG" http://localhost:8080/StorageApi/id
目前如果我运行它,它会显示这个错误:
ID=test001 : The term 'ID=test001' 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:1
+ ID=test001 ./initializeID.sh
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (ID=test001:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
【问题讨论】:
-
请记住,您不能只在 Powershell 中运行
.sh脚本。 shebang 在 Windows 中也不是一个东西。 -
详情请看链接帖子和this answer。
-
好点,@BendertheGreatest。 Tina J,您使用的语法仅适用于类似 POSIX 的 shell,例如 Bash。在 PowerShell 中,
ID=test001被解释为 命令名称,它解释了错误消息。如果您还需要翻译脚本本身:请查看Invoke-RestMethod和Invoke-WebRequest以了解类似curl的功能。 -
即使在 linux 中我也遇到了运行问题。
./initializeID.sh需要权限,没有bash就无法运行。但是我知道如何通过ID=test001那么。
标签: bash powershell cmd windows-10 sh