You'd need something like:
export REPO
az acr repository list -n registry -o tsv |
while IFS= read -r REPO; do
az acr manifest list-metadata -r "$REGISTRY" --n "$REPO" --query '[?tags[0]==null].digest' -o tsv |
awk '{print ENVIRON["REPO"]": "$0}'
done
Calling awk to prefix the output of each manifest command with the corresponding repo name.
Or if you need to run other commands on each repo/digest pair:
az acr repository list -n registry -o tsv |
while IFS= read -r repo; do
az acr manifest list-metadata -r "$REGISTRY" --n "$repo" --query '[?tags[0]==null].digest' -o tsv |
while IFS= read -r digest; do
other-cmd --repo "$repo" --digest "$digest"
done
done
With zsh, you could also do:
for repo ( ${(f)"$(az acr repository list -n registry -o tsv)"} ) {
digests=( ${(f)"$(az acr manifest list-metadata -r $REGISTRY --n $repo --query '[?tags[0]==null].digest' -o tsv)"})
print -rC1 -- $repo': '$^digests
}
for repo ( ${(f)"$(az acr repository list -n registry -o tsv)"} )
for digest ( ${(f)"$(az acr manifest list-metadata -r $REGISTRY --n $repo --query '[?tags[0]==null].digest' -o tsv)"})
other-cmd --repo $repo --digest $digest
In a Makefile, that'd look like:
target:
az acr repository list -n registry -o tsv | \
while IFS= read -r repo; do \
az acr manifest list-metadata -r "$$REGISTRY" --n "$$repo" --query '[?tags[0]==null].digest' -o tsv | \
while IFS= read -r digest; do \
other-cmd --repo "$$repo" --digest "$$digest"; \
done; \
done
While that's on several lines in the Makefile, those lines are joined together, trailing \s removed and the $$s changed to $s before passing the result to sh -c, hence the need to add a few ;s to separate commands in that inline shell script.
You may want to put the code in a script instead to make it cleaner.
azcommands, and the corresponding final output you expect. – muru Sep 09 '22 at 09:01--n %”, do you mean “--n %”, or do you mean “--n name1” (and “--n name2”)? – G-Man Says 'Reinstate Monica' Sep 09 '22 at 22:55--n %is wrong, it is--name ${REPO}which will be--name name1. I am happy to see the new solution! – Python coder Sep 10 '22 at 15:12