'bad substitution running aws-cli for-loop
I'm trying to run the below command but receiving a bad substitution error.
for i in ${aws eks list-clusters --query 'clusters' --output text | tr '\t' '\n' | grep dev-shark}; do aws eks describe-cluster --name $i | jq '.cluster.tags."Dev-Ver"'; done
see error msg below
bash: ${aws eks list-clusters --query 'clusters' --output text | tr '\t' '\n' | grep dev-shark}: bad substitution
Any ideas what maybe causing this?
Thanks.
Solution 1:[1]
I'd suggest pipe the output of the aws|tr|grep pipeline into a while read loop: adding line continuations and newlines for readability
aws eks list-clusters --query 'clusters' --output text \
| tr '\t' '\n' \
| grep dev-shark \
| while IFS= read -r line; do
aws eks describe-cluster --name "$line" \
| jq '.cluster.tags."Dev-Ver"'
done
Solution 2:[2]
The last pipe is not setting any action "| dev-shark", are you looking to filter against the text "dev-shark" then the code should be
for i in ${aws eks list-clusters --query 'clusters' --output text | tr '\t' '\n' | grep dev-shark}; do aws eks describe-cluster --name $i | jq '.cluster.tags."Dev-Ver"'; done
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | glenn jackman |
| Solution 2 | Ricardo Elena |
