Below are the two different AWS CLI commands, running on bash:

IMAGES_TO_DELETE=$( aws ecr list-images --region $ECR_REGION --repository-name $ECR_REPO --filter "tagStatus=UNTAGGED" --query 'imageIds[*]' --output json )

aws ecr batch-delete-image --region $ECR_REGION --repository-name $ECR_REPO --image-ids "$IMAGES_TO_DELETE" || true

Where first command stores JSON format [ {"imageDigest": "sha256:..."}, {"imageDigest": "sha256:..."}, ... ] in IMAGES_TO_DELETE


In a scenario, where I can run single nested command:

aws ecr batch-delete-image --region us-west-2 --repository-name "somedockerimage" --image-ids “$(aws ecr list-images --region us-west-2 --repository-name "somedockerimage" --filter "tagStatus=UNTAGGED" --query 'imageIds[*]' --output text)” || true

Donne une erreur:

Error parsing parameter '--image-ids': Expected: '=', received: '“' for input:
“sha256:cccccccccc983f4185f48fb968634dae8c4276ee1a7ffffffffffffff
^

aws ecr batch-delete-image --region us-west-2 --repository-name "somedockerimage" --image-ids “$(aws ecr list-images --region us-west-2 --repository-name "somedockerimage" --filter "tagStatus=UNTAGGED" --query 'imageIds[*]' --output json)” || true

Donne une erreur:

Error parsing parameter '--image-ids': Expected: '=', received: '“' for input:
“[
^

What is the nested syntax to replace "$IMAGES_TO_DELETE" in the second command?

0
overexchange 24 janv. 2020 à 03:12

1 réponse

Meilleure réponse

Change the smart quotes “...” to straight quotes "...".

1
John Kugelman 24 janv. 2020 à 00:21