You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

新手求助:如何在curl POST命令中正确添加变量?

问题解决方法

你的curl命令无法正常运行的核心原因是给URL变量套了多余的单引号,导致curl实际请求的地址包含单引号,服务器无法识别。

修正后的完整代码

# 获取UDID的命令
udid=$(system_profiler SPHardwareDataType | grep -i "UUID" | awk 'NR==1{print $3}')
echo "$udid"
# 也可以用更规范的变量包裹写法:url="https://xxxxxxx.jamfcloud.com/api/devices/${udid}/refresh"
url="https://xxxxxxx.jamfcloud.com/api/devices/"$udid"/refresh"
echo "$url"


# API组刷新命令
function refresh(){
    curl --location --request POST "$url" \
--header 'Authorization: Basic ********************************=' \
--header 'Cookie: hash=***********************'
}

refresh

关键修正点

  • 去掉curl命令中"'$url'"里的多余单引号,直接用"$url"即可,shell会正确解析变量为实际的URL地址
  • 额外建议:定义URL时用${udid}的形式包裹变量,能避免变量和后续字符混淆的潜在问题,写法更规范

内容的提问来源于stack exchange,提问作者Anthony

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 02:44:53