首页 > 解决方案 > 带有 curl 命令的 Shell 代码抛出格式错误的错误

问题描述

我有一个 curl 命令:

list_groups=$(curl -u GET "${name_host}/groups/listeridentifier")
echo "${list_groups}"

它返回一个错误:

curl: (3) <url> malformed

我只试过 Echo :

echo " result1 $(curl -u GET "${name_host}/groups/listeridentifier") result2"

总是返回相同的错误:

curl: (3) <url> malformed
 result 1 result2

参数 name_host 为:

http://host_name:number_port

知道当我在 API REST (HttpRequest) 中执行它时它运行良好,我只更改了主机的名称和 ssh 中的端口号。仅在我的 shell 代码中。

谁能告诉我问题出在哪里?

标签: shell

解决方案


如果您正在使用,-u那么 curl 将期待您想要充当的用户的参数。

curl --help
...
-u --user USER[:PASSWORD]  Server user and password
...

推荐阅读