Reputation:
I'm trying to execute an script in bash, but throw me this error,
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched close brace/bracket in URL position 24:
UTC","user_id":"01234"}}
i tried removing the braces but does not work, this is the line,
response=$(curl -X POST -H "Authorization: Bearer ${bearer_token}" -H "Content-Type: application/json" -d '{"cursus_user":{"begin_at":"'${start}'","cursus_id":"'${cursus_id}'","end_at":"'${end}'","user_id":"'${user}'"}}' "https://xxxxxx/xxxxxx.com")
Anyone know where is the issue?, i'm stuck, thanks in advance.
[ UPDATE ]
Really i can't see the error :(
'
{
"cursus_user":
{
"begin_at": "'${start}'",
"cursus_id": "'${cursus_id}'",
"end_at": "'${end}'",
"user_id": "'${user}'"
}
}
'
Upvotes: 0
Views: 2630
Reputation: 21129
add additional double quotes; say., "'"${start}"'"
instead of "'${start}'"
{
"cursus_user":
{
"begin_at": "'"${start}"'",
"cursus_id": "'"${cursus_id}"'",
"end_at": "'"${end}"'",
"user_id": "'"${user}"'"
}
}
Upvotes: 0
Reputation: 246847
This is really more of a formatted comment.
Two tips:
data=$(
jq --null-input \
--compact-output \
--arg begin_at "$start" \
--arg cursus_id "$cursus_id" \
--arg end_at "$end" \
--arg user_id "$user" \
'{cursus_user: $ARGS.named}'
)
curl_opts=(
-X POST
-H "Authorization: Bearer ${bearer_token}"
-H "Content-Type: application/json"
-d "$data"
)
response=$(curl "${curl_opts[@]}" "https://xxxxxx/xxxxxx.com")
Upvotes: 1
Reputation: 8084
Shellcheck identifies several unquoted variables in the curl
command. It even provides the corrected code:
response=$(curl -X POST -H "Authorization: Bearer ${bearer_token}" -H "Content-Type: application/json" -d '{"cursus_user":{"begin_at":"'"${start}"'","cursus_id":"'"${cursus_id}"'","end_at":"'"${end}"'","user_id":"'"${user}"'"}}' "https://xxxxxx/xxxxxx.com")
Using Shellcheck often saves a lot of time when working with shell code.
Upvotes: 1