CURL错误“ URL使用错误/非法格式或缺少URL”尝试将变量作为URL的一部分传递时 [英] CURL error "URL using bad/illegal format or missing URL" when trying to pass variable as a part of URL
本文介绍了CURL错误“ URL使用错误/非法格式或缺少URL”尝试将变量作为URL的一部分传递时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试执行以下脚本并出现错误时:卷曲:(3)URL使用错误/非法格式或缺少URL
When I'm trying to execute script below and getting error: "curl: (3) URL using bad/illegal format or missing URL"
#!/bin/bash
stage="develop"
branch="branch_name"
getDefinition=$(curl -u user@example.com:password -X GET "https://dev.azure.com/organization/project/_apis/build/definitions?api-version=5.1")
for def in $(echo "$getDefinition" | jq '.value[] | select (.path=="\\Some_path\\'$stage'") | .id'); do
getBuildInfo=$(curl -u user@example.com:password -X GET "https://dev.azure.com/organization/project/_apis/build/definitions/${def}\?api-version=5.1")
# echo $def
body=$(echo "${getBuildInfo}" | jq '.repository.defaultBranch = "refs/heads/release/'"${branch}"'"' | jq '.options[].inputs.branchFilters = "[\"+refs/heads/release/'"${branch}"'\"]"' | jq '.triggers[].branchFilters[] = "+refs/heads/release/'"${branch}"'"')
echo ${body} > data.json
done
当我尝试传递变量时会发生$ {def} 插入一行:
It happens when I'm trying to pass variable ${def} into a line:
curl -u user@example.com:password -X GET "https://dev.azure.com/organization/project/_apis/build/definitions/${def}\?api-version=5.1"
但是当我声明一个数组时,curl会按预期工作。
示例:
But when I declare an array, curl works as expected. Example:
declare -a def
def=(1 2 3 4)
curl -u user@example.com:password -X GET "https://dev.azure.com/organization/project/_apis/build/definitions/${def}\?api-version=5.1"
您能否建议如何将变量正确地传递到URL?
Could you please suggest how can I pass variable into URL properly?
推荐答案
是否需要调用curl 4次?
Do you need to call curl for 4 times? If so.
for def in 1 2 3 4; do curl -u user@example.com:password -X GET "https://dev.azure.com/organization/project/_apis/build/definitions/${def}\?api-version=5.1"; done
这篇关于CURL错误“ URL使用错误/非法格式或缺少URL”尝试将变量作为URL的一部分传递时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文