It is saving the content from myrootjsonfile
because that is what you are telling curl
to do - to save that file to the location assets/content.json
, and then grep
ing stdin, which is empty. You need to use two curl
commands, one to download the root file (and process it to find the URL of the second), and the second to download the actual content you want. You can use command substitution for this:
my_url=$(curl https://mysite.com/myrootjsonfile | grep -Po '(?<=url: )[^,]*')
curl -o assets/content.json "$my_url"
I also changed the grep
regex - this one matches a string of non-comma characters which follow after "url: ".