overexchange
overexchange

Reputation: 1

How to use nested AWS CLI command syntax?

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

gives error:

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

gives error:

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

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

Upvotes: 0

Views: 1597

Answers (1)

John Kugelman
John Kugelman

Reputation: 361849

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

Upvotes: 1

Related Questions