aws cli 使用 'for loop' 描述集群错误

aws cli describe cluster error using 'for loop'

我在使用 aws cli 命令 aws eks describe-cluster 尝试 运行 for 循环时遇到问题。我在执行时收到以下错误。我的脚本不是最好的。任何帮助将不胜感激。谢谢

for i in $(aws eks list-clusters | grep dev-shark); do aws eks describe-cluster --name $i | jq '.cluster.tags."Dev-Ver"'; done

An error occurred (InvalidParameterException) when calling the DescribeCluster operation: The name parameter contains invalid characters. It should begin with letter or digit and can have any of the following characters: the set of Unicode letters, digits, hyphens and underscores.

如果我只是 运行 aws eks list-clusters | grep dev-shark 它输出以下内容:

aws eks list-clusters | grep dev-shark

"dev-shark-01-eks-cluster",  
"dev-shark-02-eks-cluster",  
"dev-shark-03-eks-cluster"  

好像是逗号(,)导致的错误?如何最好地删除每行末尾的 ,?

逗号 (,) 和引号 (") 都是导致错误的原因。而不是

aws eks list-clusters | grep dev-shark

,你可以做到

aws eks list-clusters --query 'clusters' --output text | tr '\t' '\n' | grep dev-shark