我正在嘗試使用 bash 和 AQL 從 artifactory 下載一些工件。
artifacts=("blah" "blah2")
for i in ${!artifacts[@]};
do
artifact="${artifacts[$i]}*jar"
resultAsJson=$(curl -u$username:"$password" -X POST http://$host/artifactory/api/search/aql -H "content-type: text/plain" -d 'items.find({ "repo": {"$eq":"libs-release-local"}, "name": {"$match" : "*********"}})')
echo $resultAsJson
done
上面,我放的地方********,如果我放入字串文字或帶通配符的字串,它就可以作業。喜歡artifact*jar作品。
但是$artifact在 curl 評估它之前我無法對其進行評估。所以它搜索文字字串,$artifact而不是blah*jar. 我現在已經嘗試了很多東西。
uj5u.com熱心網友回復:
原因很簡單:您使用的是不擴展 shell 變數的單引號。
你必須更換:
'items.find({ "repo": {"$eq":"libs-release-local"}, "name": {"$match" : "$artifact"}})'
和:
"items.find({ \"repo\": {\"$eq\": \"libs-release-local\"}, \"name\": {\"$match\" : \"$artifact\"}})"
uj5u.com熱心網友回復:
如果你只想擴展一個變數,單引號更易讀:
'items.find({ "repo": {"$eq":"libs-release-local"}, "name": {"$match" : "'"$artifact"'"}})'
的解釋"'"$artifact"'":
- 首先 " 放入輸出字串
- First ' 完成輸出字串
- 然后將“$artifact”放入輸出字串中
- 最后
'"以 " 作為第一個字符開始另一個輸出字串。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/346496.html
下一篇:使用bash-c逐行決議
