J'ai un code qui renvoie une chaîne de jeton d'accès.Comment obtenir une chaîne spécifique à partir d'une variable à l'aide de Shell Script
#!/bin/bash
token=$(curl --globoff -X POST "https://example.com/token" -F 'grant_type=client_credentials' -F 'client_id=d86fc9b690963b8dda602bd26f33454r457e9024a4ecccf4c3bbf66ffcbc241b' -F 'client_code'='ff148c56118728b62c9f2ew3e4r009a7a1c645276b70611fa32fa055b9944934')
echo "$token" > Token.txt
La sortie donnée par cette commande est:
{
"access_token": "5048e7d38e73b4a809a4fcb219b63ae34f34f43f83d6663ffd777203afb5654ab",
"token_type": "bearer",
"expires_in": 7200
}
ie. la variable token
contient le résultat ci-dessus. Ma question est de savoir comment obtenir le jeton d'accès 5048e7d38e73b4a809a4fcb219b63ae34f34f43f83d6663ffd777203afb5654ab
seul et enregistrer dans une autre variable.
Téléchargez et installez l'utilitaire de l'analyseur 'JSON' [' jq'] (https://stedolan.github.io/jq/download/) – Inian