I have a CURL on my sh script. I need save it`s ddecoded ata.
curl -H "Content-Type: application/json" -X POST -d '{"hash":"$restearterHash"}' {$host}ApiController/jsonRestarter/ | python -m json.tool
how to save data in the varible?
You could use command substitution:
VAR=$(curl -H "Content-Type: application/json" -X POST -d '{"hash":"$restearterHash"}' {$host}ApiController/jsonRestarter/ | python -m json.tool)
echo "${VAR}"
You can store the output of a command like this: var=`command`,
so this should work fine for you:
json=`curl -H "Content-Type: application/json" -X POST -d '{"hash":"$restearterHash"}' {$host}ApiController/jsonRestarter/ | python -m json.tool`
var=$(somecommand) is the modern syntax (present in the 1991 POSIX sh standard, so present in any standard-compliant shell written or updated in more than 25 years). $() nests better than backticks, and backslash literals contained therein have less surprising behavior.
json.tooldoesn't change the output into JSON -- if json.tool accepts it as input, it's already JSON to start with.jqfor that. We already have lots of questions and answers in the knowledgebase describing how to do so; please search before you ask.