8

I am running the following curl command:

results=$(curl -USERNAME:PASSWORD "URL/search/dates?dateFields=created&from=${Three_Months_Ago}&today&repos=generic-sgca")
echo "$results"

I am getting this in return:

"results" : [ {
    "uri" : "URL/api/storage/generic-sgca/Lastest_Deploy.tar",
    "created" : "2017-09-14T11:59:14.483-06:00"
  }, {
    "uri" : "URL/api/storage/generic-sgca/Installer-Deploy-0.0.5/SignalStudioPro-Alpha-1-linux-x64-installer.run",
    "created" : "2017-09-14T20:11:37.733-06:00"
  }

It doesn't seem to actually be storing the curl results as an array. I want to be able to store each "uri" as a variable and use an "-X DELETE" command to remove each file. How can I get the "uri" line on it's own, remove the "created" option.

EDIT:

I've used the following command:

results=$(curl -username:password "URL/api/search/dates?dateFields=created&from=${Three_Months_Ago}&today&repos=generic-sgca" | jq -r '.results[].uri')
echo "$results"

I got this in return:

URL/api/storage/generic-sgca/Lastest_Deploy.tar
URL/api/storage/generic-sgca/Installer-Deploy-0.0.5/SignalStudioPro-Alpha-1-linux-x64-installer.run
URL/api/storage/generic-sgca/Installer-Deploy-0.0.5/SignalStudioPro-Alpha-1-windows-installer.exe
URL/api/storage/generic-sgca/Installer-Deploy-0.0.99/SignalStudioPro-Alpha-1-linux-x64-installer.run
URL/api/storage/generic-sgca/Installer-Deploy-0.0.99/SignalStudioPro-Alpha-1-windows-installer.exe
URL/api/storage/generic-sgca/Installer-Deploy-0.2.0/SignalStudioPro-Alpha-2-linux-x64-installer.run
URL/api/storage/generic-sgca/Installer-Deploy-0.2.0/SignalStudioPro-Alpha-2-windows-installer.exe
URL/api/storage/generic-sgca/Installer-Deploy-100.0.0/SignalStudioPro-Alpha-2-linux-x64-installer.run
URL/api/storage/generic-sgca/Installer-Deploy-100.0.0/SignalStudioPro-Alpha-2-windows-installer.exe
URL/api/storage/generic-sgca/Installer-Deploy-101.0.0/SignalStudioPro-Alpha-2-linux-x64-installer.run
URL/api/storage/generic-sgca/Installer-Deploy-101.0.0/SignalStudioPro-Alpha-2-windows-installer.exe
URL/api/storage/generic-sgca/Installer-Deploy-99.9.9/SignalStudioPro-Alpha-2-linux-x64-installer.run
URL/api/storage/generic-sgca/Installer-Deploy-99.9.9/SignalStudioPro-Alpha-2-windows-installer.exe
URL/api/storage/generic-sgca/Installer-Deploy-99.9.91/SignalStudioPro-Alpha-2-linux-x64-installer.run
URL/api/storage/generic-sgca/Installer-Deploy-99.9.91/SignalStudioPro-Alpha-2-windows-installer.exe

Now I want to run a curl -X DELETE command to delete each of those urls from my Artifactory page. The command would be:

curl username:password -X DELETE "URL FROM ABOVE"

But I can't figure out how to store each line as a separate variable so I can delete each one.

1
  • It doesn't seem to because it isn't. You are just saving a single JSON string. Commented Dec 4, 2017 at 16:06

1 Answer 1

4

Use jq to extract the URLs.

$ curl ... | jq -r '.results[].uri'
URL/api/storage/generic-sgca/Lastest_Deploy.tar
URL/api/storage/generic-sgca/Installer-Deploy-0.0.5/SignalStudioPro-Alpha-1-linux-x64-installer.run

Then use your favorite correct technique for iterating over the output of a command line-by-line; see Bash FAQ 001 for details.

(I'm assuming a URL will not contain a newline; if that's the case, switch to a different language that can handle arbitrary data more easily.)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your help, I've updated my OP. Mind taking a look? Need help storing each line as separate variables so I can delete each URL.
Did you look at Bash FAQ 001 yet?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.