Curl Error "Url Using Bad/Illegal Format or Missing Url" When Trying to Pass Variable as a Part of 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 :password -X GET "")

for def in $(echo "$getDefinition" | jq '.value[] | select (.path=="\\Some_path\\'$stage'") | .id'); do
  getBuildInfo=$(curl -u :password -X GET "")
        # 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

It happens when I'm trying to pass variable ${def} into a line:

curl -u :password -X GET ""

But when I declare an array, curl works as expected. Example:

declare -a def
def=(1 2 3 4)

curl -u :password -X GET ""

Could you please suggest how can I pass variable into URL properly?

3

1 Answer

Do you need to call curl for 4 times? If so.

for def in 1 2 3 4; do curl -u :password -X GET ""; done
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest