Add variable into url curl command 将变量添加到URL curl命令中

huangapple go评论71阅读模式
英文:

Add variable into url curl command

问题

Sure, here's the translated part of your code:

# Command to retrieve the UDID

udid=$(system_profiler SPHardwareDataType | grep -i "UUID" | awk 'NR==1{print $3}')
echo "$udid"
url="https://xxxxxxx.jamfcloud.com/api/devices/"$udid"/refresh"
echo "$url"

# Command to add to the API group

function refresh(){
	curl --location --request POST "$url" \
	--header 'Authorization: Basic ********************************=' \
	--header 'Cookie: hash=***********************'
}

refresh

Is there anything else you need help with?

英文:

I want to add a variable into my curl POST command. My level is very low...

I try something, but doesn't work...

# Commande pour récupérer l'UDID

udid=$(system_profiler SPHardwareDataType | grep -i "UUID" | awk 'NR==1{print $3}')
echo "$udid"
url="https://xxxxxxx.jamfcloud.com/api/devices/"$udid"/refresh"
echo "$url"


# Commande pour ajout groupe API

function refresh(){
	curl --location --request POST "'"$url"'" \
--header 'Authorization: Basic ********************************=' \
--header 'Cookie: hash=***********************'
}

refresh

答案1

得分: 1

Don't wrap the URL in single quotes in the curl command. In other words instead of

curl --location --request POST "$url"

Related to that is this line:

url="https://xxxxxxx.jamfcloud.com/api/devices/$udid/refresh"
英文:

Don't wrap the URL in single quotes in the curl command. In other words instead of

curl --location --request POST "'"$url"'"

do

curl --location --request POST "$url"

Related to that is this line:

url="https://xxxxxxx.jamfcloud.com/api/devices/"$udid"/refresh"

should simply be

url="https://xxxxxxx.jamfcloud.com/api/devices/$udid/refresh"

huangapple
  • 本文由 发表于 2023年8月4日 20:58:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76836139.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定