-1

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?

sinica
  • 99
  • 1
  • 7

2 Answers2

0

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`

Florian Fray
  • 274
  • 1
  • 6
  • `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. – Charles Duffy Sep 30 '17 at 13:57
  • Also, see [How to Answer](https://stackoverflow.com/help/how-to-answer) in the help center, particularly the section "Answer Well-Asked Questions", *particularly* the section requesting that one not answer questions that have been asked and answered many times before. – Charles Duffy Sep 30 '17 at 13:58
0

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}"
  • Welcome to StackOverflow, and thank you for using proper code formatting and providing a link to authoritative documentation! That said, note the section "Answer Well-Asked Questions" in [How to Answer](https://stackoverflow.com/help/how-to-answer), particularly the following bullet point regarding questions which "*have already been asked and answered many times before*". – Charles Duffy Sep 30 '17 at 14:16