如何在AWS CLI输出中循环显示? [英] How to I loop through AWS CLI output?
问题描述
我正在尝试将aws cli查询的值列表传递给另一个命令.即使我在AWS中看到了很多示例,当我尝试将所有值组合在一起时:
I am trying to pass a list of values from a aws cli query to another command. Even though I have seen plenty of examples in AWS, when I try all the values come together:
policy_versions=`aws iam list-policy-versions --query "Versions[].VersionId" --policy-arn $POLICY_ARN --output text`
echo "policy_versions=$policy_versions"
for ver in $policy_versions; do
echo "first version: $ver"
done
然后打印出来:
policy_versions=v3 v2 v1
first version: v3 v2 v1
我的 ver
值是整个字符串,应为 v3
,然后为 v2
和 v1
.而是: v3 v2 v1
.
My value of ver
is the entire string, it should be v3
then v2
and v1
. But It is instead:
v3 v2 v1
.
我不知道怎么了.
推荐答案
我能够重现您的结果,并且将结果追溯到shell和 zsh
(现在用作是MacOS中的默认外壳).
I was able to reproduce your results and I traced the results to a difference between shell and zsh
(which is now used as the default shell in MacOS).
简单地输入,您可以运行此命令以使其按预期的方式工作: setopt shwordsplit
Put simply, you can run this command to make it work the way you expect: setopt shwordsplit
有关更多详细信息,请参见:迭代-Shell脚本-迭代以空格分隔的单词/字符(在zsh中)-堆栈溢出
For more details, see: iteration - Shell script - iterate over space separated words/characters (in zsh) - Stack Overflow
这篇关于如何在AWS CLI输出中循环显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!