Bash 将结果存储到数组中

Viv*_*obo 6 arrays bash curl

我正在运行以下 curl 命令:

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

我得到这个回报:

"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"
  }
Run Code Online (Sandbox Code Playgroud)

它似乎实际上并未将 curl 结果存储为数组。我希望能够将每个“uri”存储为变量并使用“-X DELETE”命令删除每个文件。我怎样才能自己获得“uri”行,删除“created”选项。

编辑:

我使用了以下命令:

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

我得到了这个回报:

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
Run Code Online (Sandbox Code Playgroud)

现在我想运行 curl -X DELETE 命令来从我的 Artifactory 页面中删除每个 url。命令将是:

curl username:password -X DELETE "URL FROM ABOVE"
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚如何将每一行存储为一个单独的变量,以便我可以删除每一行。

che*_*ner 3

用于jq提取 URL。

$ 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
Run Code Online (Sandbox Code Playgroud)

然后使用您最喜欢的正确技术逐行迭代命令行的输出;有关详细信息,请参阅Bash 常见问题解答 001

(我假设 URL 不会包含换行符;如果是这种情况,请切换到可以更轻松地处理任意数据的其他语言。)