替换错误 运行 aws-cli for-loop
bad substitution running aws-cli for-loop
我正在尝试 运行 以下命令,但收到错误的替换错误。
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
查看下面的错误消息
bash: ${aws eks list-clusters --query 'clusters' --output text | tr '\t' '\n' | grep dev-shark}: bad substitution
知道是什么原因造成的吗?
谢谢。
最后一个管道未设置任何操作“|dev-shark”,您是否要针对文本“dev-shark”进行过滤,那么代码应该是
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
我建议将 aws|tr|grep
管道的输出通过管道传输到 while read
循环中:添加续行符和换行符以提高可读性
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
我正在尝试 运行 以下命令,但收到错误的替换错误。
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
查看下面的错误消息
bash: ${aws eks list-clusters --query 'clusters' --output text | tr '\t' '\n' | grep dev-shark}: bad substitution
知道是什么原因造成的吗?
谢谢。
最后一个管道未设置任何操作“|dev-shark”,您是否要针对文本“dev-shark”进行过滤,那么代码应该是
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
我建议将 aws|tr|grep
管道的输出通过管道传输到 while read
循环中:添加续行符和换行符以提高可读性
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