无与伦比的闭合支架/支架

发布于 2025-02-02 17:50:57 字数 876 浏览 5 评论 0原文

我正试图在Bash中执行一个脚本,但是把这个错误扔了,

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"}}

我尝试删除牙套,但不起作用,这是行,

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")

任何人都知道问题在哪里?

[更新]

我真的看不到错误:(

'
{
    "cursus_user":
    {
        "begin_at":     "'${start}'",
        "cursus_id":    "'${cursus_id}'",
        "end_at":       "'${end}'",
        "user_id":      "'${user}'"
    }
}
'

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}'"
    }
}
'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

俯瞰星空 2025-02-09 17:50:57

这实际上是格式的评论。

两个提示:

  • 使用 jq 生成json-将使您的所有报价正确使用,
  • 请使用阵列可读性(我不喜欢水平滚动)
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")

This is really more of a formatted comment.

Two tips:

  • use to generate JSON -- it will get all the quoting correct for you
  • use arrays for readability (I dislike scrolling horizontally)
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")
神回复 2025-02-09 17:50:57

shellCheck 标识curl命令中的几个未引用的变量。它甚至提供了校正的代码:

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")

使用 shellCheck 在使用Shell Code时,通常会节省很多时间。

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.

无所的.畏惧 2025-02-09 17:50:57

添加其他双引号;说。,“'” $ {start}“'”而不是“'$ {start}'”

{
    "cursus_user":
    {
        "begin_at":     "'"${start}"'",
        "cursus_id":    "'"${cursus_id}"'",
        "end_at":       "'"${end}"'",
        "user_id":      "'"${user}"'"
    }
}

add additional double quotes; say., "'"${start}"'" instead of "'${start}'"

{
    "cursus_user":
    {
        "begin_at":     "'"${start}"'",
        "cursus_id":    "'"${cursus_id}"'",
        "end_at":       "'"${end}"'",
        "user_id":      "'"${user}"'"
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文