英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论