小编loc*_*cal的帖子

尝试将变量作为 URL 的一部分传递时,出现 CURL 错误“使用错误/非法格式的 URL 或缺少 URL”

当我尝试执行下面的脚本并收到错误时:“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
Run Code Online (Sandbox Code Playgroud)

当我尝试将变量${def}传递到一行时会发生这种情况:

curl -u user@example.com:password -X GET "https://dev.azure.com/organization/project/_apis/build/definitions/${def}\?api-version=5.1"
Run Code Online (Sandbox Code Playgroud)

但是当我声明一个数组时,curl 按预期工作。例子:

declare -a def
def=(1 2 3 …
Run Code Online (Sandbox Code Playgroud)

bash curl jq

15
推荐指数
2
解决办法
3万
查看次数

标签 统计

bash ×1

curl ×1

jq ×1